mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-08-28 04:46:29 -04:00
Add new element style 'enumeration', used for items in ordered lists
This commit is contained in:
+22
-3
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user