I use Hugo mostly for documentation. One thing that I would love to be able to do is to use readFile
to pull in code files from outside the Markdown document and have the pulled-in code properly syntax highlighted. But at the moment this doesn’t seem to be possible in Hugo because Chroma doesn’t “see” that material as highlightable. Have any of you found a way around this?
To provide a more concrete example, I would love for something like this to work:
<!-- layouts/shortcodes/code.html -->
<div class="highlight">
<pre>
<code class="language-python">
{{ readFile (.Get 0) }}
</code>
</pre>
</div>
But it seems that the stage of the page building cycle at which Chroma operates doesn’t allow for it.
Now, I am aware that this should be possible using Highlight.js or another client-side highlighter. But it would be great to have native support for it in Hugo.
If this doesn’t seem to be possible, I’d also love pointers on how this could be made possible in Hugo. I’d be happy to do that work.