Merge pull request #11325 from JanetKuo/toc
Make MUNGE generated TOC bookmark work for symbols
This commit is contained in:
@@ -75,6 +75,9 @@ func buildTOC(markdown []byte) ([]byte, error) {
|
||||
if numSharps > 0 {
|
||||
indent := strings.Repeat(" ", numSharps-1)
|
||||
bookmark := strings.Replace(strings.ToLower(heading), " ", "-", -1)
|
||||
// remove ' and ? in bookmarks
|
||||
bookmark = strings.Replace(bookmark, "?", "", -1)
|
||||
bookmark = strings.Replace(bookmark, "'", "", -1)
|
||||
tocLine := fmt.Sprintf("%s- [%s](#%s)\n", indent, heading, bookmark)
|
||||
buffer.WriteString(tocLine)
|
||||
}
|
||||
|
@@ -37,6 +37,10 @@ func Test_buildTOC(t *testing.T) {
|
||||
"# Title\nLorem ipsum \n## Section Heading\ndolor sit amet\n```bash\n#!/bin/sh\n```",
|
||||
"- [Title](#title)\n - [Section Heading](#section-heading)\n",
|
||||
},
|
||||
{
|
||||
"# Title\nLorem ipsum \n## Section Heading\n### Why doesn't this work?\ndolor sit amet\n",
|
||||
"- [Title](#title)\n - [Section Heading](#section-heading)\n - [Why doesn't this work?](#why-doesnt-this-work)\n",
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
actual, err := buildTOC([]byte(c.in))
|
||||
|
Reference in New Issue
Block a user