all repos — grayfriday @ 411a019e2d24ef772cfd0d7dddfdf1f0845a7a0c

blackfriday fork with a few changes

Merge pull request #124 from halostatue/fix-header-id-toc-rendering

Use supplied header ID for TOC rendering.
Vytautas Ĺ altenis vytas@rtfb.lt
Tue, 28 Oct 2014 16:34:44 +0200
commit

411a019e2d24ef772cfd0d7dddfdf1f0845a7a0c

parent

05b8cefd6a3cd87b81adb83479f5faadc0df2a67

1 files changed, 13 insertions(+), 4 deletions(-)

jump to
M html.gohtml.go

@@ -207,7 +207,7 @@ }

// are we building a table of contents? if options.flags&HTML_TOC != 0 { - options.TocHeader(out.Bytes()[tocMarker:], level) + options.TocHeaderWithAnchor(out.Bytes()[tocMarker:], level, id) } out.WriteString(fmt.Sprintf("</h%d>\n", level))

@@ -693,7 +693,7 @@ }

} -func (options *Html) TocHeader(text []byte, level int) { +func (options *Html) TocHeaderWithAnchor(text []byte, level int, anchor string) { for level > options.currentLevel { switch { case bytes.HasSuffix(options.toc.Bytes(), []byte("</li>\n")):

@@ -719,14 +719,23 @@ }

options.currentLevel-- } - options.toc.WriteString("<li><a href=\"#toc_") - options.toc.WriteString(strconv.Itoa(options.headerCount)) + options.toc.WriteString("<li><a href=\"#") + if anchor != "" { + options.toc.WriteString(anchor) + } else { + options.toc.WriteString("toc_") + options.toc.WriteString(strconv.Itoa(options.headerCount)) + } options.toc.WriteString("\">") options.headerCount++ options.toc.Write(text) options.toc.WriteString("</a></li>\n") +} + +func (options *Html) TocHeader(text []byte, level int) { + options.TocHeaderWithAnchor(text, level, "") } func (options *Html) TocFinalize() {