4

Code blocks predominantly containing HTML are always highlighted as CSS the moment a question bears the tag, regardless of whether or not the tag is present. I always need to force HTML blocks in questions and their answers to highlight correctly using the

<!-- language: lang-html -->

or

<!-- language-all: lang-html -->

hints.

EDIT: I've found that including the tag also causes (X?)HTML to be correctly highlighted without the need for hints (see for example this question), but I don't think I should need to add/replace tags to fix this kind of problem.

IME, it's highly unlikely that a code block starting with a < character is CSS, as < isn't seen anywhere in CSS code except within strings and comments. Even if, in a block, CSS is embedded within HTML <style> tags, as long as I make that block highlight as HTML, the content of the <style> tags also correctly highlights as CSS anyway:

<style type="text/css">
/* This is CSS */
.example {
    color: red;
}
</style>
<!-- This is HTML -->
<p class="example">See? Even meta does it right.</p>

The only corner case I can think of is when HTML and CSS are trapped in a single code block like this without any <style> tags:

<p class="example">HTML paragraph.</p>

.example {
    color: red;
}

Other than that, if the syntax highlighter can already sniff HTML/XML blocks in other questions (based in part on the < character), what stops it from doing so for questions?

  • 2
    Yeah, this is a bit annoying. I can never be bothered to fix it. Can you fix my other 1000 answers? :) – thirtydot Jul 25 '11 at 13:20
  • @thirtydot: Now that you ask... no. /trollface – BoltClock's a Unicorn Jul 25 '11 at 13:38
2

Irrelevant -- the actual prettify styles for the tags are:

  • -- lang-css
  • -- lang-default

See the rules here:

Changes to syntax highlighting

  1. If a question has no tags with a default or specific language hint, no syntax highlighting will be performed.

  2. If a question has at most one tag with a specific language hint, plus any number of default or null hints, then syntax highlighting will be performed only for that specific language.

  3. If a question has two tags that both define specific languages, it uses default and lets prettify infer as it always has.

  4. As long as a question has one or more tags with default language hints, but none with a specific language hint, it uses default and let prettify infer as it always has.

  • Does this mean [html] has a default hint to stop prettify from going default on questions with other specific tags? – BoltClock's a Unicorn Aug 6 '11 at 5:12
  • did you read the above list? pay special attention to #2. – Jeff Atwood Aug 6 '11 at 5:32
  • 3
    I did, but my next question is why [html] uses the default hint. – BoltClock's a Unicorn Aug 6 '11 at 6:00

You must log in to answer this question.

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