External code files for syntax highlighting

I want to write all my code in extern files like foo.rs and then include this file in a blog post. I also want to highlight it “offline”, no js clientside rendering.

From https://gohugo.io/content-management/syntax-highlighting/

{{< highlight go "linenos=table,hl_lines=8 15-17,linenostart=199" >}}
// ... code
{{< / highlight >}}

Instead of writing the code inside this block, can I link to an external file?

{{< highlight go "file=src/foo.rs" >}}
{{< / highlight >}}

Is this possible in hugo?

Alternatively can you include html in .md files?

I use Org for content instead of Markdown, so I can confirm that Org allows referencing just to the file names for source blocks, with optional start/end line numbers.

I haven’t used Pandoc Markdown, but I am aware that that also allows something like that. Hugo development verison (master branch) supports Pandoc as external renderer. So that might be one option, if Org doesn’t fly for you.

Regarding the question about HTML In Markdown… Yes, you can embed any kind of HTML in the Markdown content.

See the readFile template func.

@MaikKlein I completely forgot about readFile as @bep suggested. That reminded me of the docfile shortcode in the Hugo doc site source.