all repos — grayfriday @ 60026cc3c65e1585f73b8f5ecab98c145487882f

blackfriday fork with a few changes

Make ListData a nested struct instead of pointer
Vytautas Ĺ altenis vytas@rtfb.lt
Fri, 01 Apr 2016 11:21:25 +0300
commit

60026cc3c65e1585f73b8f5ecab98c145487882f

parent

2a07386455d11afe616a6184c03e88a1c969316b

4 files changed, 22 insertions(+), 35 deletions(-)

jump to
M block.goblock.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 @@ for itemIndent < 3 && data[itemIndent] == ' ' {

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 @@

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 {
M html.gohtml.go

@@ -1045,15 +1045,15 @@ if node.Prev == nil {

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 @@ r.cr(w)

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 @@ // if (start !== null && start !== 1) {

// 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 @@ }

} 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 {
M markdown.gomarkdown.go

@@ -469,12 +469,7 @@ p.tip = p.doc

finalizeHtmlBlock(p.addBlock(HtmlBlock, []byte(`<div class="footnotes">`))) 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 @@ // the fixed initial set.

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)
M node.gonode.go

@@ -66,7 +66,7 @@ return nodeTypeNames[t]

} type ListData struct { - Flags ListType + ListFlags ListType Tight bool // Skip <p>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 @@

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