diff --git a/block.go b/block.go index 0d24969..ee8a78c 100644 --- a/block.go +++ b/block.go @@ -1109,12 +1109,8 @@ func (p *parser) list(data []byte, flags ListType) int { i := 0 flags |= ListItemBeginningOfList block := p.addBlock(List, nil) - block.ListData = &ListData{ // TODO: fill in the real ListData - Flags: flags, - Tight: true, - BulletChar: '*', - Delimiter: 0, - } + block.ListFlags = flags + block.Tight = true for i < len(data) { skip := p.listItem(data[i:], &flags) @@ -1184,9 +1180,12 @@ func (p *parser) listItem(data []byte, flags *ListType) int { itemIndent++ } + var bulletChar byte = '*' i := p.uliPrefix(data) if i == 0 { i = p.oliPrefix(data) + } else { + bulletChar = data[i-2] } if i == 0 { i = p.dliPrefix(data) @@ -1327,12 +1326,10 @@ gatherlines: rawBytes := raw.Bytes() block := p.addBlock(Item, nil) - block.ListData = &ListData{ // TODO: fill in the real ListData - Flags: *flags, - Tight: false, - BulletChar: '*', - Delimiter: 0, - } + block.ListFlags = *flags + block.Tight = false + block.BulletChar = bulletChar + block.Delimiter = '.' // Only '.' is possible in Markdown, but ')' will also be possible in CommonMark // render the contents of the list item if *flags&ListItemContainsBlock != 0 && *flags&ListTypeTerm == 0 { diff --git a/html.go b/html.go index 4d0b8a3..5f92f63 100644 --- a/html.go +++ b/html.go @@ -1045,15 +1045,15 @@ func itemOpenCR(node *Node) bool { return false } ld := node.Parent.ListData - return !ld.Tight && ld.Flags&ListTypeDefinition == 0 + return !ld.Tight && ld.ListFlags&ListTypeDefinition == 0 } func skipParagraphTags(node *Node) bool { grandparent := node.Parent.Parent - if grandparent == nil || grandparent.ListData == nil { + if grandparent == nil || grandparent.Type != List { return false } - tightOrTerm := grandparent.ListData.Tight || node.Parent.ListData.Flags&ListTypeTerm != 0 + tightOrTerm := grandparent.Tight || node.Parent.ListFlags&ListTypeTerm != 0 return grandparent.Type == List && tightOrTerm } @@ -1261,10 +1261,10 @@ func (r *HTML) RenderNode(w io.Writer, node *Node, entering bool) { break case List: tagName := "ul" - if node.ListData.Flags&ListTypeOrdered != 0 { + if node.ListFlags&ListTypeOrdered != 0 { tagName = "ol" } - if node.ListData.Flags&ListTypeDefinition != 0 { + if node.ListFlags&ListTypeDefinition != 0 { tagName = "dl" } if entering { @@ -1273,7 +1273,7 @@ func (r *HTML) RenderNode(w io.Writer, node *Node, entering bool) { // attrs.push(['start', start.toString()]); // } r.cr(w) - if node.Parent.Type == Item && node.Parent.Parent.ListData.Tight { + if node.Parent.Type == Item && node.Parent.Parent.Tight { r.cr(w) } r.out(w, tag(tagName, attrs, false)) @@ -1293,10 +1293,10 @@ func (r *HTML) RenderNode(w io.Writer, node *Node, entering bool) { } case Item: tagName := "li" - if node.ListData.Flags&ListTypeDefinition != 0 { + if node.ListFlags&ListTypeDefinition != 0 { tagName = "dd" } - if node.ListData.Flags&ListTypeTerm != 0 { + if node.ListFlags&ListTypeTerm != 0 { tagName = "dt" } if entering { diff --git a/markdown.go b/markdown.go index 12727d6..f36634c 100644 --- a/markdown.go +++ b/markdown.go @@ -469,12 +469,7 @@ func (p *parser) parseRefsToAST() { finalizeHtmlBlock(p.addBlock(HtmlBlock, []byte(`
`))) p.addBlock(HorizontalRule, nil) block := p.addBlock(List, nil) - block.ListData = &ListData{ // TODO: fill in the real ListData - Flags: ListTypeOrdered, - Tight: false, - BulletChar: '*', - Delimiter: 0, - } + block.ListFlags = ListTypeOrdered flags := ListItemBeginningOfList // Note: this loop is intentionally explicit, not range-form. This is // because the body of the loop will append nested footnotes to p.notes and @@ -483,13 +478,8 @@ func (p *parser) parseRefsToAST() { for i := 0; i < len(p.notes); i++ { ref := p.notes[i] block := p.addBlock(Item, nil) - block.ListData = &ListData{ // TODO: fill in the real ListData - Flags: ListTypeOrdered, - Tight: false, - BulletChar: '*', - Delimiter: 0, - RefLink: ref.link, - } + block.ListFlags = ListTypeOrdered + block.RefLink = ref.link if ref.hasBlock { flags |= ListItemContainsBlock p.block(ref.title) diff --git a/node.go b/node.go index 4c9f498..1627442 100644 --- a/node.go +++ b/node.go @@ -66,7 +66,7 @@ func (t NodeType) String() string { } type ListData struct { - Flags ListType + ListFlags ListType 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 @@ -93,7 +93,7 @@ type Node struct { Level uint32 // If Type == Header, this holds the heading level number Literal []byte - ListData *ListData // If Type == List, this holds list info + ListData // If Type == List, this holds list info // TODO: move these fenced code block fields to a substruct IsFenced bool // If Type == CodeBlock, specifies whether it's a fenced code block or an indented one Info []byte // If Type == CodeBlock, this holds the info string