Make MUNGE generated table of contents (TOC) bookmark work when there are symbols in the headline

This commit is contained in:
Janet Kuo
2015-07-15 11:26:51 -07:00
parent 8f3c3108b8
commit de755bf59b
13 changed files with 23 additions and 16 deletions

View File

@@ -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)
}