-2

As can be seen is this image here, hello appears to have syntax highlighting when the language is specified like this. <!-- language: lang-python -->. This can also be seen is this image here.

enter image description here

This is pretty odd, and I'm wondering if this is an unintentional bug, or some tricky Easter egg. Just to see, I'm going to test it here too to see if it works on other sites than just meta.SE.

Hello, this is a test.
0

1 Answer 1

12

The syntax highlighter has no knowledge of the Python interactive interpreter format, and interprets the Hello, this is a test. line as code.

It simply highlighted Hello as a type (in Python, anything with a capital initial is assumed to be a class or type). Up until this the line could have been an expression, after all. is is recognised as a language keyword and highlighted as such.

>>> print (
    "Firstword, is highlighted as an identifier. It does not matter if it is\n"
    "Hello or something else. \"Quotes\" look like 'strings'.")
Firstword, is highlighted as an identifier. It does not matter if it is
Hello or something else. "Quotes" look like 'strings'.

This is hardly the fault of the language parser however; the interpreter is echoing 'random' text in between valid code and the parser has no way of knowing what is supposed to be code and what is text.

Note that bugs in how a specific language is marked up, should be reported to the Google prettify project, not to Stack Exchange.

6
  • So don't put both code and output into the same code block. Use lang-none to suppress code highlighting.
    – Jongware
    Jul 5, 2014 at 15:36
  • @Jongware: I simply put up with the highlighting idiosyncrasies. In the end it doesn't really matter.
    – Martijn Pieters Mod
    Jul 5, 2014 at 15:38
  • @MartijnPieters Do I guess correctly based on your last comment that you are a fan of Linkin Park? Jul 5, 2014 at 15:48
  • @JanDvorak: Heh, not really. I have Hybrid Theory but I wasn't consciously referring to the track, nor am I specifically a fan. :-)
    – Martijn Pieters Mod
    Jul 5, 2014 at 15:51
  • It's highlighted because it's capitalised, which the parser will interpret as a class name. If it was all lower case (and not a keyword) it'd escape... I agree though, it doesn't matter much and could be a possible future improvement to Prettify.
    – Ben
    Jul 5, 2014 at 16:05
  • @Ben: Right; it uses typ, the highlight for types and classes, indeed.
    – Martijn Pieters Mod
    Jul 5, 2014 at 16:09

You must log in to answer this question.

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