0

In this question, I tried to use each of the following in turn, but none had effect:

  • <!-- language: none -->
  • <!-- language: text -->
  • <!-- language: xml -->

The effect expected is the same as on the SO site, where I can set the language for rendering code blocks, or disable it with none. Is this a bug or intended behavior or should I use different syntax?

Some tests

For these tests to have some discernible effect I have set the language for the whole post to lang-c, which renders the coloring as the first bullet below.

  • Test with language: nothing set (takes the default)

    <html lang="joy">some code</html>
    
  • Test with language: none

    <html lang="joy">some code</html>
    
  • Test with language: lang-none

    <html lang="joy">some code</html>
    
  • Test with language: lang-rubbish

    <html lang="joy">some code</html>
    
  • Test with language: nosuchlang

    <html lang="joy">some code</html>
    
  • Test with language: xml

    <html lang="joy">some code</html>
    
  • Test with language: lang-xml

    <html lang="joy">some code</html>
    
  • Test with language: html

    <html lang="joy">some code</html>
    
  • Test with language: lang-html

    <html lang="joy">some code</html>
    
  • Test with language: text

    <html lang="joy">some code</html>
    
  • Test with language: lang-text

    <html lang="joy">some code</html>
    
  • Test with language: plain

    <html lang="joy">some code</html>
    
  • Test with language: lang-plain

    <html lang="joy">some code</html>
    

As can be seen from the tests above, the first answer is correct, at least in part, for the meta site. But these methods still don't work on the SQA site.

These tests also show that if the language is not recognized, the hint is (indeed) ignored, but none appears to be valid values. Interesting to see that lang-rubbish results in html (or xml) rendering...

4

the language: ... syntax doesn't work unless the comment directly precedes the code block. Also, there are two ways to indicate a language: tag or lang-code. The tag-name only works if the tag exists and there's a default highlighter specified for that tag - but the tags and do not exist, so those won't work as highlighter hints; you'll want lang-xml or lang-none.

To recap: put <!-- language-all: lang-xml --> at the top of your post to set the highlighter for all code blocks in that post. Put <!-- language: lang-xml --> directly before a specific code block to set the highlighter for just that block.

Example

<this>bogus<xml>is highlighted</xml></this>

See also: syntax highlighting for code

9
  • 1
    Thanks, but still won't work. It works here, but not in the SQA question. I changed it to lang-none, it had no effect. On SO, just none works, so there clearly is a difference. I am aware of the fact that it must imm. precede the code section, but I did so in the referred to question
    – Abel
    Sep 12 '15 at 15:38
  • See my edit, @Abel - you need to use language-all to alter all code for the post. If you want to just alter the highlighting for that first (quoted) block, you'll need to work around an odd bug in how the hint-parser interacts with Markdown.
    – Shog9
    Sep 12 '15 at 15:51
  • I have updated my question with a bunch of tests to see how it works on Meta. But these tests do not work on SQA. The confirm some of your findings, but not all, i.e., none is a valid token to disable highlighting.
    – Abel
    Sep 12 '15 at 15:51
  • Shog, thanks, I see your edit, that works!
    – Abel
    Sep 12 '15 at 15:52
  • You're gonna get different results here on meta because there are no tag-specific default highlighters defined here (to my knowledge at least) - so the default (with no hint) will be "lang-none". On main, results will vary depending on which tags are used on the question - many tags simply default to, well, lang-default - which tries to guess and will often be wrong for, say, XPath.
    – Shog9
    Sep 12 '15 at 15:54
  • I think I understand now what is happening in the tests (I updated), when you choose lang-rubbish, it works as if lang-default is chosen and it guesses, like you say. Using a hint that does not follow lang-xxx style (except for none), simply chooses the default for the post (by tags), or language-all in the OP here, if present. Apparently, on SO they have extended this system to allow short-codes, because there it works with vb, xml, html without lang- prefix, if I want to override the default.
    – Abel
    Sep 12 '15 at 16:00
  • On SO, all those short codes are tags w/ default highlighters. Try "selenium" on main...
    – Shog9
    Sep 12 '15 at 16:10
  • Ah, you mean that if I write <!-- language: sometagname -->, it will take the language code (even if not present on the post) related to that tag? And because SQA has not configured any language hints for these tags, it fails? Is that why on a tags info page we see at the bottom the highlighter configured?
    – Abel
    Sep 12 '15 at 16:12
  • Yup, that's how it works!
    – Shog9
    Sep 12 '15 at 16:13

You must log in to answer this question.

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