fix issue where lists that didn't start at 1 were not respected (#116)

This commit is contained in:
R. Aidan Campbell
2021-08-12 03:45:29 +02:00
committed by GitHub
parent 8ea7b1c86c
commit 49f2da7fed
5 changed files with 21 additions and 1 deletions
+4
View File
@@ -129,6 +129,9 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element {
} }
if node.Parent().(*ast.List).IsOrdered() { if node.Parent().(*ast.List).IsOrdered() {
e = l e = l
if node.Parent().(*ast.List).Start != 1 {
e += uint(node.Parent().(*ast.List).Start) - 1
}
} }
post := "\n" post := "\n"
@@ -153,6 +156,7 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element {
return Element{ return Element{
Exiting: post, Exiting: post,
Renderer: &ItemElement{ Renderer: &ItemElement{
IsOrdered: node.Parent().(*ast.List).IsOrdered(),
Enumeration: e, Enumeration: e,
}, },
} }
+2 -1
View File
@@ -7,12 +7,13 @@ import (
// An ItemElement is used to render items inside a list. // An ItemElement is used to render items inside a list.
type ItemElement struct { type ItemElement struct {
IsOrdered bool
Enumeration uint Enumeration uint
} }
func (e *ItemElement) Render(w io.Writer, ctx RenderContext) error { func (e *ItemElement) Render(w io.Writer, ctx RenderContext) error {
var el *BaseElement var el *BaseElement
if e.Enumeration > 0 { if e.IsOrdered {
el = &BaseElement{ el = &BaseElement{
Style: ctx.options.Styles.Enumeration, Style: ctx.options.Styles.Enumeration,
Prefix: strconv.FormatInt(int64(e.Enumeration), 10), Prefix: strconv.FormatInt(int64(e.Enumeration), 10),
+3
View File
@@ -0,0 +1,3 @@
3. 3 is first and numbered 3
4. 4 is second and numbered 4
10. ten is third and numbered 5
+8
View File
@@ -0,0 +1,8 @@
{
"list": {
"level_indent": 1
},
"enumeration": {
"block_prefix": ". "
}
}
+4
View File
@@ -0,0 +1,4 @@
3. 3 is first and numbered 3
4. 4 is second and numbered 4
5. ten is third and numbered 5