This question already has an answer here:

According to the editing help:

You can use either one of the supported prettify language codes, like lang-cpp or lang-sql, or you can specify a tag, and the syntax highlighting language associated with this tag will be used:

<!-- language: c# -->

    public static bool IsAwesome { get { return true; } }

However, in this revision history, <!-- language: python --> fails, yet <!-- language: lang-py --> works. is clearly a valid tag, so I'd expect both to work

This also would explain why questions tagged do not automatically use python syntax highlighting

share|improve this question
This is a duplicate. I can feel it. – Cole Johnson 2 days ago
1  
python is associated with the default highlighter, not lang-py, so this behaviour is expected. Now, I don't know why python isn't associated with the lang-py highlighter, so that might be unintentional. – Tim Stone 2 days ago
...Or not, Jeff seems to classify it as a "webby language", which means it gets the default highlighter. – Tim Stone 2 days ago
1  
@TimStone: I don't think I've seen a single python question with an HTML block in. – Eric 2 days ago
Yeah, you might be able to make a case for having the associated highlighter changed. – Tim Stone 2 days ago
3  
Python is so not a webby language. Jeff's assertion is way off the mark there. – Martijn Pieters 2 days ago
Hey, I can change that! Interesting. But is there another problem that changing it away from the default causes? The whole syntax highlighting system is hopelessly broken. – minitech 2 days ago
1  
@minitech: I am willing to find out! Change it, change it NAUOW! – Martijn Pieters 2 days ago
@MartijnPieters: Well, here we go! – minitech 2 days ago

marked as duplicate by Tim Stone, kiamlaluno, Łukasz Lech, Jim, Cody Gray yesterday

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

up vote 2 down vote accepted

I changed it, as Python is really not a “web language”.

Let’s see what sort of horrible consequences arise… :(

share|improve this answer

What described in the help is correct, except that in the case the tag is using the default highlighter, the syntax highlighting language will be guessed.

On Drupal Answers, I associated lang-php with the "views" tag, and wrote the following code in a question.

<!-- language: views -->

    function check_plain($text) {
      return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
    }

The syntax highlighting language was correctly applied.

screenshot

Probably the help text should make that clear.

You can use either one of the supported prettify language codes, like lang-cpp or lang-sql, or you can specify a tag, and the syntax highlighting language associated with that tag will be used, if the tag is associated with a syntax highlighting language different from the default one:

<!-- language: c# -->

    public static bool IsAwesome { get { return true; } }

As a matter of fact, a tag could be set not to be associated with any syntax highlighting language.

screenshot

That is different from using the default syntax highlighting language, though.

screenshot

share|improve this answer
2  
a tag could be set not to be associated with any syntax highlighting language. Exactly, and that is the problem here. Python has no syntax highlighting associated with it, but it should. It doesn't because Jeff Atwood made the wrong call. – Martijn Pieters 2 days ago
@MartijnPieters is it true that Jeff Atwood gets an automatic downvote by Community♦ on every answer that he posts under the feature tag? – Jan Dvorak 2 days ago
It is as close as automatic :-P – Martijn Pieters 2 days ago
@MartijnPieters Nope, that is different. Using no syntax highlighting language is different from using the default one: In the first case, no highlighting will be done; in the second case, the syntax highlighting language will be guessed. – kiamlaluno 2 days ago
Right, that wasn't clear from your post. Note that Minitech switched the highlighter now, so we should be seeing proper highlighting on Python posts from here on out. – Martijn Pieters 2 days ago
@MartijnPieters That solves it for questions using python, but it doesn't avoid users would be confused by an tag using the default syntax highlighting language, and for which the syntax highlighter is not able to guess the language used in the snippet. – kiamlaluno 2 days ago

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