Skip to content

Commit

Permalink
fix: Indentation fix for TOC (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
traut authored Sep 2, 2024
1 parent d1305b2 commit d45f94e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion internal/builtin/content_toc.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ func (n tocNode) render(pos, depth int, ordered bool) string {
if ordered {
format = "%s" + strconv.Itoa(pos+1) + ". [%s](#%s)\n"
}
const indentStep = " "
dst := []string{
fmt.Sprintf(format, strings.Repeat(" ", depth), n.title, anchorize(n.title)),
fmt.Sprintf(format, strings.Repeat(indentStep, depth), n.title, anchorize(n.title)),
n.children.render(depth+1, ordered),
}
return strings.Join(dst, "")
Expand Down
6 changes: 3 additions & 3 deletions internal/builtin/content_toc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func (s *TOCContentTestSuite) TestSimple() {
s.Len(diags, 0, "no errors")
s.Equal(strings.Join([]string{
"- [Header 1](#header-1)",
" - [Header 2](#header-2)",
" - [Header 3](#header-3)",
" - [Header 2](#header-2)",
" - [Header 3](#header-3)",
}, "\n")+"\n", mdprint.PrintString(res.Content))
}

Expand Down Expand Up @@ -164,7 +164,7 @@ func (s *TOCContentTestSuite) TestAdvanced() {
s.Len(diags, 0, "no errors")
s.Equal(strings.Join([]string{
"1. [Header 2](#header-2)",
" 1. [Header 3](#header-3)",
" 1. [Header 3](#header-3)",
"2. [Header 4](#header-4)",
"3. [Header 5](#header-5)",
}, "\n")+"\n", mdprint.PrintString(res.Content))
Expand Down

0 comments on commit d45f94e

Please sign in to comment.