diff --git a/html.go b/html.go index 3d20866..a85f918 100644 --- a/html.go +++ b/html.go @@ -207,7 +207,7 @@ func (options *Html) Header(out *bytes.Buffer, text func() bool, level int, id s // 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("\n", level)) @@ -693,7 +693,7 @@ func (options *Html) DocumentFooter(out *bytes.Buffer) { } -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("\n")): @@ -719,8 +719,13 @@ func (options *Html) TocHeader(text []byte, level int) { options.currentLevel-- } - options.toc.WriteString("
  • ") options.headerCount++ @@ -729,6 +734,10 @@ func (options *Html) TocHeader(text []byte, level int) { options.toc.WriteString("
  • \n") } +func (options *Html) TocHeader(text []byte, level int) { + options.TocHeaderWithAnchor(text, level, "") +} + func (options *Html) TocFinalize() { for options.currentLevel > 1 { options.toc.WriteString("\n")