Fix table of contents for hugo

Hugo has some hardcoded checks that have to be fulfilled in its Table of
Contents extraction workflow (helpers/content ExtractTOC). It's easier this
way...
This commit is contained in:
Niklas Fasching 2018-12-26 18:53:31 +01:00
parent 940b1c7125
commit d3d3b6c593
4 changed files with 34 additions and 65 deletions

View file

@ -216,7 +216,8 @@ func (w *HTMLWriter) writeOutline(d *Document) {
}
func (w *HTMLWriter) writeSection(section *Section) {
w.WriteString("<li>\n")
// NOTE: To satisfy hugo ExtractTOC() check we cannot use `<li>\n` here. Doesn't really matter, just a note.
w.WriteString("<li>")
h := section.Headline
title := cleanHeadlineTitleForHTMLAnchorRegexp.ReplaceAllString(w.nodesAsString(h.Title...), "")
w.WriteString(fmt.Sprintf("<a href=\"#%s\">%s</a>\n", h.ID(), title))