From 01fe90630cf3f502e96ee05fd533556e8b1cdabb Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 8 Jul 2021 14:05:35 -0400 Subject: [PATCH] feat: handle braces in header text --- testdata/special.md | 1 + testdata/special_toc.md | 2 ++ toc.go | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/testdata/special.md b/testdata/special.md index bd76079..f703cb1 100644 --- a/testdata/special.md +++ b/testdata/special.md @@ -19,3 +19,4 @@ An example document with headers including special/uncommon characters to test g ## 'With single quotes' +## {With braces} diff --git a/testdata/special_toc.md b/testdata/special_toc.md index cc55938..5317fdf 100644 --- a/testdata/special_toc.md +++ b/testdata/special_toc.md @@ -11,6 +11,7 @@ An example document with headers including special/uncommon characters to test g * [`With backticks`](#with-backticks) * ["With double quotes"](#with-double-quotes) * ['With single quotes'](#with-single-quotes) +* [{With braces}](#with-braces) ## With/Slash @@ -30,3 +31,4 @@ An example document with headers including special/uncommon characters to test g ## 'With single quotes' +## {With braces} diff --git a/toc.go b/toc.go index 7b9e518..d9d81ec 100644 --- a/toc.go +++ b/toc.go @@ -135,7 +135,7 @@ func Parse(b []byte) (*Toc, error) { // ex. `Header One Two` = `header-one-two` func textToLink(s string) string { // TODO: find a more comprehensive/formally documented list of these - rep := strings.NewReplacer(" ", "-", "/", "", ",", "", ".", "", "+", "", ":", "", ";", "", "`", "", `"`, "", `'`, "") + rep := strings.NewReplacer(" ", "-", "/", "", ",", "", ".", "", "+", "", ":", "", ";", "", "`", "", `"`, "", `'`, "", "{", "", "}", "") return strings.ToLower(rep.Replace(s)) }