1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-10-31 23:53:01 +00:00

Add anchor links

This commit is contained in:
bouncepaw
2021-03-02 21:36:57 +05:00
parent f45758cb0e
commit fbf94975aa
7 changed files with 72 additions and 15 deletions

View File

@@ -4,6 +4,8 @@ import (
"fmt"
"html"
"strings"
"github.com/bouncepaw/mycorrhiza/util"
)
// HyphaExists holds function that checks that a hypha is present.
@@ -83,7 +85,8 @@ func lineToAST(line string, state *GemLexerState, ast *[]Line) {
return strings.HasPrefix(line, token)
}
addHeading := func(i int) {
addLine(fmt.Sprintf("<h%d id='%d'>%s</h%d>", i, state.id, ParagraphToHtml(state.name, line[i+1:]), i))
id := util.LettersNumbersOnly(line[i+1:])
addLine(fmt.Sprintf(`<h%d id='%d'>%s<a href="#%s" id="%s" class="heading__link"></a></h%d>`, i, state.id, ParagraphToHtml(state.name, line[i+1:]), id, id, i))
}
// Beware! Usage of goto. Some may say it is considered evil but in this case it helped to make a better-structured code.