Disable syntax highlighted for a page/layout

Hi All,

Does anyone know if it is possible to disable syntax highlighting only on certain pages/layouts in my Jekyll site? I found I can enable/disable all syntax highlighting on my entire site by adding highlighter: none to _config.yml, but I would like to have syntax highlighting enabled everywhere except certain pages, (or better yet, layouts). For example, it would be awesome if I could just add highlighter: none to the yaml header for a single page.


Alright! After a bit more searching I found this thread which suggests a way of passing options to kramdown on a per-page basis. Combining that with the suitable kramdown option, I found that adding the following line to a page disables syntax highlighting for that page only

{::options syntax_highlighter="nil" /}

Crisis averted.

Do you mean code that is syntax highlighted? I don’t know what else you would highlight

You can use backticks or indentation and you’ll get plain black text in monospace.

My code


    My code

And if you want to enable highlighting them you supply a language.

My code

Or you use the highlight Jekyll tag.

Thanks for the comment @MichaelCurrin . Yes, my question refers to syntax highlighting in code presented on my site. The syntax highlighting in your example was working the way that that I expected. The issue arose because I am using reveal.js to render some pages on my site as slides using the method described here. For code presented on the slides, I wanted to use the reveal.js styling, but for code on regular non-slide pages, I wanted the kramdown rouge syntax highlighting.

The problem was that if syntax highlighting was enabled site-wide, kramdown compiled code in the markdown file for a slide to html, then reveal.js would interpret the generated html as code and render that. So instead of rendering

    for int(i = 0; i < max; i++) {
      // do something

on my slides, I would get some monstrosity like this:

  <span class="k">for</span> <span class="kt">int</span><span class="o">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">max</span><span class="o">;</span> <span class="n">i</span><span class="o">++)</span> <span class="o">{</span>
    <span class="c1">// do something</span>
  <span class="o">}</span>

When I turned off syntax highlighting globally for my site by setting highlighter: none, the code rendered properly on my slides, but then I lost syntax highlighting everywhere else on the site. The fix that I mentioned above is to add

{::options syntax_highlighter="nil" /}

to the top of each page that will be rendered using reveal.js. With this option set, kramdown doesn’t stylize the code on my slides (but still does elsewhere on my site) and the highlighting is handled by reveal.js.

Anyway, sorry if my original post was entirely too vague! For now, I am happy to have everything working as I want it to, even if the solution feels a little hack-y.

1 Like

Thanks for added details.

That reminds me, I have been meaning to get into using reveal.js