Add new element style 'enumeration', used for items in ordered lists

This commit is contained in:
Christian Muehlhaeuser
2019-12-05 10:05:15 +01:00
parent 1e195cc3de
commit 82d6db7c7d
2 changed files with 25 additions and 3 deletions
+22 -3
View File
@@ -2,6 +2,7 @@ package gold
import (
"io"
"strconv"
bf "gopkg.in/russross/blackfriday.v2"
)
@@ -10,9 +11,27 @@ type ItemElement struct {
}
func (e *ItemElement) Render(w io.Writer, node *bf.Node, tr *TermRenderer) error {
el := &BaseElement{
Token: string(node.Literal),
Style: Item,
var el *BaseElement
if node.ListData.ListFlags&bf.ListTypeOrdered > 0 {
var l int64
n := node
for n.Prev != nil && (n.Prev.Type == bf.Item) {
l++
n = n.Prev
}
el = &BaseElement{
Token: string(node.Literal),
Style: Enumeration,
Prefix: strconv.FormatInt(l+1, 10),
}
} else {
el = &BaseElement{
Token: string(node.Literal),
Style: Item,
}
}
return el.Render(w, node, tr)
}
+3
View File
@@ -11,6 +11,7 @@ const (
BlockQuote
List
Item
Enumeration
Paragraph
Heading
HorizontalRule
@@ -90,6 +91,8 @@ func keyToType(key string) (StyleType, error) {
return List, nil
case "item":
return Item, nil
case "enumeration":
return Enumeration, nil
case "paragraph":
return Paragraph, nil
case "heading":