I know there is existing topic about how to including anther md file into current md file.
The popular way is to use shortcode, so I create a shortcode ‘include’ like the following
{{ $file := .Get 0 }}
{{ if strings.HasSuffix $file ".html" }}
{{ $file | readFile | safeHTML }}
{{ else if strings.HasSuffix $file ".md" }}
{{ $file | readFile | markdownify }}
{{ end }}
and use that shortcode like this
<!-- Requests library introduction -->
{{% include "share/py/requests.md" %}}
The big problem of it is , the headings of included markdown file will NOT be put into the TOC of current md file.
I noticed there is a description in Hugo doc, Shortcodes | Hugo.
In Hugo
0.55
we changed how the%
delimiter works. Shortcodes using the%
as the outer-most delimiter will now be fully rendered when sent to the content renderer (e.g. Blackfriday for Markdown), meaning they can be part of the generated table of contents, footnotes, etc.
But that just did not work, the headings inside of the included md still missing.
My hugo version is : hugo_extended_0.61.0_Windows-64bit
Is there anying I missed?
I packaged all relevant files in my project into a tiny zip file.
https://github.com/jcyrss/baiyueheiyu/files/4007660/hugo-demo.zip
Just unzip it, run ‘hugo server’, and browse address ''http://localhost:1313/tut/03/" will show the problem.
As the following screenshot shows, headings in included md are missed, while I did use shortcode like {{% include "share/requests.md" %}}
in the file content\tut\03.md