I’m using Jekyll to build a documentation website and I’ve run into an issue when including other HTML in Jekyll. Part of my documentation is built automatically from the source code (using odoc). This generates JSON files which contains metadata about each page and a fully rendered html content. I use a small ruby plugin to detect all those json files and generate a jekyll page for each.
These pages use a layout that looks like this:
---
layout: default
---
<div class="odoc">
{{ page.odoc.content }}
</div>
My problem is that the {{ page.odoc.content }}
doesn’t include the json string verbatim, it strips newlines and repeated spaces. How can I prevent this ?
This is an issue because odoc generates two separate code block styles:
- One is for code blocks inside documentation comments, these are wrapped in
<pre><code>
blocks and are rendered correctly (whitespace preserved) - The other is for code from the source itself. These don’t use
<pre>
blocks, they are only rendered in<code>
and usewhite-space: pre-wrap;
to render. These are the blocks whose formatting breaks.
I’ve tried using {{ page.odoc.content | newlines_to_br }}
, and it doesn’t help. For one, it breaks the first code block, whose newlines have now been doubled. Furthermore, while it does render newlines correctly for the second code block type, it doesn’t preserve indentation (multiple successive spaces are still replaced by a single space).