55

Possible Duplicate:
Interface options for specifying language prettify

I don't know how Markdown recognizes which language to use in code blocks. Sometimes it doesn't guess right. Can I specify a code block's language myself? If so, how?

6
  • 1
    It used Google Prettify meta.stackexchange.com/questions/14664/…. Your question pretty much dups this meta.stackexchange.com/questions/981/…, and lots of others. Commented Jan 7, 2011 at 8:56
  • 2
    Is this really a feature request? It doesn't sound like one. If you want a possibility to choose the language yourself, then this is a dupe. Right now, only the algorithm determines the "correct" language. Commented Jan 7, 2011 at 8:57
  • @Shog9 it seems wrong to close a specific question by calling it a duplicate of a generic question, even if the answer is somewhere in there. Commented Nov 6, 2017 at 20:09
  • The answer has changed over time, @BobStein-VisiBone - the linked question is kept up to date, this answer probably won't be. Commented Nov 6, 2017 at 23:56
  • 9
    <!-- language: «lang-or-tag-here» --> in stackoverflow, ` ```«lang-or-tag-here» ` elsewhere... Commented Sep 24, 2018 at 12:53
  • BTW, should add <!-- language: xxx --> before code block ```, not inside. Commented Apr 19, 2023 at 8:41

1 Answer 1

22

(Note, I'm answering the body of your question, not the title)

The tags on your question are used to determine the language for the code blocks.

I'm not sure how that works if you have multiple languages in your tags, or for code golf questions.

6
  • 1
    You can't specify any tag in answer, isn't it? Commented Jan 7, 2011 at 12:51
  • 5
    Yup, see here: meta.stackexchange.com/questions/72082/… Commented Jan 7, 2011 at 12:54
  • github.com/googlearchive/code-prettify/blob/master/README.md Commented Dec 13, 2021 at 22:26
  • 2
    Use <!-- language:javascript --> or <!-- language:typescript --> Commented Nov 9, 2022 at 16:57
  • Thanks Alexander, this was exactly what I was looking for and works like a charm as of 2024. Commented Aug 10, 2024 at 16:39
  • As of 2024 use something like ```javascript to start the code block, and ``` to end it. See full details here: meta.stackexchange.com/questions/184108/… Stack Overflow uses Highlight.js now, having dropped Prettify in 2020. Commented Dec 11, 2024 at 16:12

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.