From cdeeb608e70e1e00b34ce3a882a19debb8acb230 Mon Sep 17 00:00:00 2001 From: Yagiz Degirmenci Date: Wed, 20 Jan 2021 04:38:55 +0300 Subject: [PATCH] feat: use asteriks for headers > h1 --- pkg/toc/toc.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/toc/toc.go b/pkg/toc/toc.go index cc4f881..9305a3a 100644 --- a/pkg/toc/toc.go +++ b/pkg/toc/toc.go @@ -89,16 +89,19 @@ func getHeaderValue(header string) int { return headers[header] } -func (t *toc) parseHTML(body []byte) error { - var f func(*html.Node) - var delimiter string - +func (t *toc) getDelimiter(header int) string { // Set delimiter if t.Options.Bulleted == true { - delimiter = "-" - } else { - delimiter = "1." + if header >= 1 { + return "*" + } + return "-" } + return "1." +} + +func (t *toc) parseHTML(body []byte) error { + var f func(*html.Node) parsedMD, err := convertToHTML(body) if err != nil { @@ -109,7 +112,9 @@ func (t *toc) parseHTML(body []byte) error { f = func(n *html.Node) { if n.Type == html.ElementNode && isHeader(n.Data) { - t.add(fmt.Sprintf("%s%s [%s](#%s)\n", strings.Repeat(tab, getHeaderValue(n.Data)), delimiter, n.FirstChild.Data, n.Attr[0].Val)) + headerVal := getHeaderValue(n.Data) + val := fmt.Sprintf("%s%s [%s](#%s)\n", strings.Repeat(tab, headerVal), t.getDelimiter(headerVal), n.FirstChild.Data, n.Attr[0].Val) + t.add(val) } for c := n.FirstChild; c != nil; c = c.NextSibling {