Skip to content

Commit a7c0e70

Browse files
committed
feat(parser): add ids to headings
1 parent 6c40747 commit a7c0e70

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

parser/tags.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ type Heading struct {
2929
}
3030

3131
func (p Heading) String() string {
32-
return fmt.Sprintf("<h%d>%s</h%d>", p.lvl, p.text, p.lvl)
32+
text := strings.TrimSpace(p.text)
33+
return fmt.Sprintf("<h%d id=\"%s\">%s</h%d>", p.lvl, text, text, p.lvl)
3334
}
3435

3536
type Quote struct {
@@ -91,17 +92,11 @@ func (p TodoListItem) String() string {
9192

9293
type CodeBlock struct {
9394
language string
94-
children []string
95+
text string
9596
}
9697

9798
func (p CodeBlock) String() string {
98-
b := strings.Builder{}
99-
b.WriteString("<code class=\"code-lang-" + p.language + "\"><pre>")
100-
for _, v := range p.children {
101-
b.WriteString(v)
102-
}
103-
b.WriteString("</pre></code>")
104-
return b.String()
99+
return fmt.Sprintf("<pre class=\"%s\"><code>%s</code></pre>", p.language, p.text)
105100
}
106101

107102
type CodeInline struct {

0 commit comments

Comments
 (0)