diff --git a/ast/node.go b/ast/node.go
index 6fe70cd..825b343 100644
--- a/ast/node.go
+++ b/ast/node.go
@@ -137,6 +137,7 @@ type List struct {
Tight bool // Skip
s around list item data if true
BulletChar byte // '*', '+' or '-' in bullet lists
Delimiter byte // '.' or ')' after the number in ordered lists
+ Start int // for ordered lists this indicates the starting number if > 0
RefLink []byte // If not nil, turns this list item into a footnote item and triggers different rendering
IsFootnotesList bool // This is a list of footnotes
}
diff --git a/html/renderer.go b/html/renderer.go
index 6089e56..0d03e98 100644
--- a/html/renderer.go
+++ b/html/renderer.go
@@ -653,6 +653,9 @@ func (r *Renderer) listEnter(w io.Writer, nodeData *ast.List) {
openTag := "
0 {
+ attrs = append(attrs, fmt.Sprintf(`start="%d"`, nodeData.Start))
+ }
openTag = " 0 {
- data = data[p.list(data, 0):]
+ data = data[p.list(data, 0, 0):]
continue
}
@@ -237,8 +238,15 @@ func (p *Parser) block(data []byte) {
//
// 1. Item 1
// 2. Item 2
- if p.oliPrefix(data) > 0 {
- data = data[p.list(data, ast.ListTypeOrdered):]
+ if i := p.oliPrefix(data); i > 0 {
+ start := 0
+ if i > 2 {
+ start, _ = strconv.Atoi(string(data[:i-2])) // this cannot fail because we just est. the thing *is* a number.
+ if start == 1 {
+ start = 0
+ }
+ }
+ data = data[p.list(data, ast.ListTypeOrdered, start):]
continue
}
@@ -252,7 +260,7 @@ func (p *Parser) block(data []byte) {
// : Definition c
if p.extensions&DefinitionLists != 0 {
if p.dliPrefix(data) > 0 {
- data = data[p.list(data, ast.ListTypeDefinition):]
+ data = data[p.list(data, ast.ListTypeDefinition, 0):]
continue
}
}
@@ -1192,12 +1200,13 @@ func (p *Parser) dliPrefix(data []byte) int {
}
// parse ordered or unordered list block
-func (p *Parser) list(data []byte, flags ast.ListType) int {
+func (p *Parser) list(data []byte, flags ast.ListType, start int) int {
i := 0
flags |= ast.ListItemBeginningOfList
list := &ast.List{
ListFlags: flags,
Tight: true,
+ Start: start,
}
block := p.addBlock(list)
@@ -1533,7 +1542,7 @@ func (p *Parser) paragraph(data []byte) int {
// did this blank line followed by a definition list item?
if p.extensions&DefinitionLists != 0 {
if i < len(data)-1 && data[i+1] == ':' {
- listLen := p.list(data[prev:], ast.ListTypeDefinition)
+ listLen := p.list(data[prev:], ast.ListTypeDefinition, 0)
return prev + listLen
}
}
@@ -1600,7 +1609,7 @@ func (p *Parser) paragraph(data []byte) int {
// if there's a definition list item, prev line is a definition term
if p.extensions&DefinitionLists != 0 {
if p.dliPrefix(current) != 0 {
- ret := p.list(data[prev:], ast.ListTypeDefinition)
+ ret := p.list(data[prev:], ast.ListTypeDefinition, 0)
return ret + prev
}
}