Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

25
  • 3
    Shouldn't there be an indicated preference (not rule) here in this answer for using either a language code or a tag name (possibly with some qualifiers)? E.g. "Prefer to use X over Y, unless Z." (Somewhat related question on MSO (in comments): What's the difference between the two code formatting styles (code-fences vs indented blocks) regarding syntax highlighting?) Commented Oct 16, 2020 at 16:00
  • 1
    and it will use whatever language code is currently associated with that tag Is there an official list of these mappings available anywhere? Commented Oct 29, 2020 at 1:05
  • Section 4, "4. Check that the tags on the question have syntax highlighting enabled", has all the info to find out @JoshGoebel Commented Oct 29, 2020 at 5:41
  • 1
    @Josh To your direct question, I don't believe there is a list anywhere currently containing all tags with associated language, however. It also doesn't look like this info is accessible using SEDE either, it's not in the tags table.
    – zcoop98
    Commented Oct 29, 2020 at 14:32
  • 11
    @Wolf The lang- prefix isn't redundant. As mentioned in the post above, ```lang-javascript tells the highlighter to use the JS highlighter directly, while ```javascript alone tells it to look at the highlighter set for the tag [javascript]. They aren't always the same (maybe most notably with [typescript] on Stack Overflow).
    – zcoop98
    Commented Mar 11, 2021 at 16:09
  • 2
    Thanks a lot for clarifying. The post has so much text that it's hard to find this information. The tags I use obviously have the right highlighting connected to them, so it's easy to get the impression of redundancy for most people.
    – Wolf
    Commented Mar 11, 2021 at 16:56
  • 1
    Is there a way to determine what syntax highlighting code is being applied to a given code block? For example, in instances where none of the tags are associated with language codes and so lang-default is used, I'd like to know which language highlight.js ultimately settled on based on the auto-recognition (since if I find one I like, I can manually specify it in future, as lang-default gives different results question to question even if I use the same language).
    – Greedo
    Commented Mar 21, 2021 at 15:47
  • I don't know @Greedo - perhaps worth a separate question. Commented Mar 22, 2021 at 13:54
  • 1
    @Greedo You can sometimes tell by inspecting the code block on page using browser dev tools- I've found it somewhat inconsistent in the past, but most of the time the selected/ detected language itself is listed as a class on the code block. (Example)
    – zcoop98
    Commented Mar 22, 2021 at 15:00
  • 1
    @LeonardoAlvesMachado If you want it in an enterprise version of Stack Exchange, then you're probably best off asking for it through whatever official support channel for the product. Doing so will probably have significantly more weight wrt. getting it done than anything you can post on the public network. Posting a comment is ineffective. Posting a feature-request question might be? effective, but probably not. The answer to: "Julia syntax highlighting" is the current official response for any requests for additional languages on the public network.
    – Makyen
    Commented Nov 19, 2021 at 16:35
  • @EvgenKo423 Do you have a source for the claim that questions using only tags with no syntax highlighting identifiers will not be highlighted at all vs. highlighted with automatic detection? Also, the name of the library is "highlight.js", not "Highlight.js"; the lowercasing was intentional. Commented Nov 22, 2021 at 19:25
  • @Sonic [1/2] Yes, it's stated in a question linked in that paragraph.
    – EvgenKo423
    Commented Nov 23, 2021 at 8:28
  • @Sonic [2/2] As for the name, it's a library vs. project name issue (oh, I hate those projects called after the library, especially if the authors can't decide on official consistent variant...). If you take a look at Highlight.js readme you'll see that they mostly use the upper-case variant, even in a middle of a sentence. Library name is appropriate when referencing the file, while here it's being referenced as a project. And even then the real name of the library used by Stack Exchange is highlightjs-loader.en.js, not highlight.js.
    – EvgenKo423
    Commented Nov 23, 2021 at 8:30
  • 1
    @EvgenKo423 I wasn't aware of the convention at the time I wrote the answer. The editor who added that text initially and I were going off the project's website, which uses the lowercase name. Also, I did test the highlighter's behavior and it indeed doesn't highlight if none of the tags have identifiers specified; I thought things had changed since the linked question was posted, since a then-moderator in 2014 edited in the text here that they're automatically parsed. Commented Nov 23, 2021 at 10:13
  • 1
    @SamuelMuldoon That use case (using a tag name instead of a lang- specifier) is covered a few times; first under the "How do I use syntax highlighting?" heading, and then again under "Hinting: Tags".
    – zcoop98
    Commented Aug 15, 2022 at 15:23