What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 128 Stack Exchange communities.

I've noticed, that comments (noticed this at least in Delphi language) are not highlighted as comments at this time. A few examples:

http://stackoverflow.com/a/15297489/960757
http://stackoverflow.com/a/15237273/960757

Notice that lines escaped by // chars should not be highlighted as code, but as comments:

enter image description here

Could you take a look on it, please ?

share|improve this question
    
This seems to have been caused by meta.stackexchange.com/questions/171666/… –  Matt Mar 14 '13 at 22:23
    
It seems to do so. It's nice to have a specific highlighter, but it broke a lot of answers now due to a missing <!-- language: lang-pascal.js --> tag. –  TLama Mar 14 '13 at 22:28
    
lang-pascal should be enough. lang-pascal.js would apply the default guesser. The 'broken' highlighting is when pascal is used as the highlighter. –  Martijn Pieters Mar 14 '13 at 22:29
add comment

3 Answers 3

up vote 12 down vote accepted

The default pascal highlighter coming from the prettify project is bogus.

Based on it, I've made a new Delphi Google prettify highlighter that, not being perfect, address the following issues:

  • The backslash is not treated as an escape character in strings, so for example S := 'C:\' + Path now correctly ends the string.
  • The three flavors of comments are recognized and correctly highlighted: { }, (* *) block comments and a la c // end of line comments
  • The list of reserved words is updated to Delphi XE3 official list. I decided to include only the reserved words and not directives (in the sense of the linked document). That excludes words like absolute, override and the like, that you may want to see highlighted. The problem here is the words are not reserved and have a special meaning only when used in certain constructions, but the language allows also to use it as identifiers (that's discouraged, but allowed). I'm not sure about this, but I wanted the job finished. Let's see the comment trail here to make a final decision.

I consider the new highlighter not final, but it works better than the old one. Your bug reports and feature requests are welcome.

Marc Gravell kindly accepted it to use it here in SO while I post it to the official prettify project, as noted in his answer comments. It will be used not as lang-delphi but as lang-pascal. I'll update here if my proposal gets official acceptance.

share|improve this answer
1  
Such contribution deserves the answer accept! Special thanks to @Marc for his job as well! –  TLama Mar 15 '13 at 16:21
    
May I have a question about the highlighter ? If a reserved word is contained as a part of an identifier, e.g. var SomeName_string_var_etc: string it is treated as a reserved word and highlighted that way. Is there a way to fix this ? Look e.g. at this post. –  TLama Aug 22 '13 at 10:49
add comment

Sigh. As noted, I don't think there is a lang-delphi. So: we have a few options:

  • use lang-pascal and accept fixed string literals at the expense of code comments
  • use lang-default and prefer comments to working string literals
  • hope someone will volunteer a patch to lang-pascal

I'm all ears.

Update:

I've put jachguate's version in (after testing etc) as lang-pascal for now; long term this would ideally by contributed by the author to the prettify code-base (see also my comments below).

share|improve this answer
1  
The first option is too expensive in my view. I'd prefer to break those escapes again and stop to highlight code comments. Even the answers in the post linked to the yesterday's question are worse readable now (due to those highlighted comments). The third option would of course be the best. –  TLama Mar 14 '13 at 23:11
2  
@Marc I did once a HTML highlighter for Delphi. Please, point me in the right direction of where can I check how the highlighting is done here to check if I can contribute. Of course the third option is the best! –  jachguate Mar 14 '13 at 23:32
    
@jachguate we use prettify from google-code –  Marc Gravell Mar 15 '13 at 0:00
1  
@Marc, I've created a new lang-delphi prettify extension, and uploaded it. I don't consider this to be final, but it fixes the commenting and problems with strings ending with a backslash () I observed in SO. It would be nice if others contribute with bug reports to enhance the extension, but IMHO it's superior to the lang-pascal we use now. –  jachguate Mar 15 '13 at 5:54
    
@jachguate I've tested that and it seems to do the job; however, being pragmatic it may be preferable to propose it (to the prettify project) as changes to the existing lang-pascal one; the line between pascal and delphi is blurry and the two terms are often used interchangeably or incorrectly. I don't think the prettify project will want a lang-pascal and a lang-delphi. For now, I'm using your version as lang-pascal (not lang-delphi) –  Marc Gravell Mar 15 '13 at 9:12
    
@Marc I asked myself that question before posting it here, but the list of reserved words also varies from the old days of Turbo Pascal, so I wasn't sure. Being user of Turbo Pascal and Delphi, I'm aware of what was changed, but I'm not familiar with free pascal or other pascal flavors. I'll ponder the idea a bit more in my head and I'll post as a proposal to the prettify project, as Delphi or Pascal in the coming days. Thanks for taking my contribution, I hope it really improves the experience here. I'll also post an answer to this question to let the OP accept it ;) –  jachguate Mar 15 '13 at 16:06
add comment

It's the Pascal highlighter that is at fault here.

If you add a lang-delphi hint the highlighting is correct:

<!-- language: lang-delphi -->

I honestly do not know if there is a Delphi highlighter, but the first answer you linked looks correct now that I added it. It may be that the default highlighter is better than the Pascal highlighter for these posts.

share|improve this answer
    
So there seems to be also a lang-delphi language. Though lang-pascal helped for this too. Well, this doesn't make me happy as I'm having a lot of posts to update now... And some people a lot more than me. Thanks for the answer! –  TLama Mar 14 '13 at 22:41
    
@TLama: No, don't update the posts. Let the devs alter the language hint attached to the tag instead. See Pascal/Delphi syntax highlighting should ignore \' escape characters where I asked Marc to use lang-delphi for the Delphi tag instead. –  Martijn Pieters Mar 14 '13 at 22:43
    
@TLama: No there is no lang-delphi language hint. What's actually happening is that the identifier is not recognized, so it's reverting to lang-default. –  animuson Mar 14 '13 at 22:44
    
Oh, I see. So the lang-pascal should be a default highlighter for the questions tagged by delphi, pascal, freepascal, object-pascal and turbo-pascal, but that's not implemented yet. –  TLama Mar 14 '13 at 22:55
    
@TLama lang-pascal is the default for delphi and pascal; I can add it to the other 3 tomorrow –  Marc Gravell Mar 14 '13 at 22:57
    
@Marc, that would be great, thanks! –  TLama Mar 14 '13 at 23:11
add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .