1

Using github flavored markdown, there are three sytnax variants for a block of code:

  1. Fenced code blocks

    ```js
    var user = "string"
    ```
    
  2. Indented code blocks

        var user = "string"
    
  3. Html blocks example 137

    <pre><code>var user = <i>"string"</i>
    </code></pre>
    

Github will also apply syntax highlighting when parsing markdown files, but I can't get it to work for indented or html blocks.

How can I tell github to run syntax highlighting or even specify a language for indented code blocks or html code blocks?

Here's a gist with a working demo of github's markdown parsing

1 Answer 1

2

In GitHub Flavored Markdown Spec it says:

The line with the opening code fence may optionally contain some text following the code fence; this is trimmed of leading and trailing whitespace and called the info string. (...) The content of a code fence is treated as literal text, not parsed as inlines. The first word of the info string is typically used to specify the language of the code sample, and rendered in the class attribute of the code tag.

And earlier it also says:

An indented code block has no info string.

So I think it's not possible to embed language information in indented code blocks. To put language information inside HTML block I found this to be working ok:

<pre lang="javascript"><code>var user = "string"
</code></pre>

Here is a short test on Github: https://gist.github.com/ardrabczyk/179e05e0a2134389de3d270c2a10ee26

2
  • Oh, sweet!! I'm a sucker for throwing samples inside <pre><code> blocks and escaping myself so I can throw in some extra <b> or <i> tags to empahsize sections within the code. This'll help bunches. Thanks!
    – KyleMit
    Dec 31, 2018 at 1:09
  • Ahh, definitely answers the question, but didn't happen to solve my roundabout problem. Now that syntax highlighting is being applied to html blocks, it's sanitizing the tags inside them
    – KyleMit
    Dec 31, 2018 at 1:16

You must log in to answer this question.

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