rename item => listItem

This commit is contained in:
Krzysztof Kowalczyk 2018-01-26 22:23:27 -08:00
parent 41105f379c
commit 55ffc5cd59
6 changed files with 24 additions and 26 deletions

View File

@ -1182,7 +1182,7 @@ func endsWithBlankLine(block *Node) bool {
//return true
//}
switch block.Data.(type) {
case *ListData, *ItemData:
case *ListData, *ListItemData:
block = block.LastChild
default:
return false
@ -1376,7 +1376,7 @@ gatherlines:
rawBytes := raw.Bytes()
d := &ItemData{
d := &ListItemData{
ListFlags: *flags,
Tight: false,
BulletChar: bulletChar,

View File

@ -346,7 +346,7 @@ func skipParagraphTags(node *Node) bool {
if grandparent == nil || !isListData(grandparent.Data) {
return false
}
isParentTerm := isItemTerm(parent)
isParentTerm := isListItemTerm(parent)
grandparentListData := grandparent.Data.(*ListData)
tightOrTerm := grandparentListData.Tight || isParentTerm
return tightOrTerm
@ -564,8 +564,8 @@ func (r *HTMLRenderer) paragraphEnter(w io.Writer, node *Node, nodeData *Paragra
}
func (r *HTMLRenderer) paragraphExit(w io.Writer, node *Node, nodeData *ParagraphData) {
r.out(w, []byte("</p>"))
if !(isItemData(node.Parent.Data) && node.Next == nil) {
r.outs(w, "</p>")
if !(isListItemData(node.Parent.Data) && node.Next == nil) {
r.cr(w)
}
}
@ -607,7 +607,7 @@ func (r *HTMLRenderer) heading(w io.Writer, node *Node, nodeData *HeadingData, e
if !entering {
closeTag := headingCloseTagFromLevel(nodeData.Level)
r.outs(w, closeTag)
if !(isItemData(node.Parent.Data) && node.Next == nil) {
if !(isListItemData(node.Parent.Data) && node.Next == nil) {
r.cr(w)
}
return
@ -658,7 +658,7 @@ func (r *HTMLRenderer) listEnter(w io.Writer, node *Node, nodeData *ListData) {
r.cr(w)
}
r.cr(w)
if isItemData(node.Parent.Data) {
if isListItemData(node.Parent.Data) {
grand := node.Parent.Parent
if isListTight(grand.Data) {
r.cr(w)
@ -683,7 +683,7 @@ func (r *HTMLRenderer) listExit(w io.Writer, node *Node, nodeData *ListData) {
//if node.parent.Type != Item {
// cr(w)
//}
if isItemData(node.Parent.Data) && node.Next != nil {
if isListItemData(node.Parent.Data) && node.Next != nil {
r.cr(w)
}
if isDocumentData(node.Parent.Data) || isBlockQuoteData(node.Parent.Data) {
@ -702,7 +702,7 @@ func (r *HTMLRenderer) list(w io.Writer, node *Node, nodeData *ListData, enterin
}
}
func (r *HTMLRenderer) item(w io.Writer, node *Node, nodeData *ItemData, entering bool) {
func (r *HTMLRenderer) listItem(w io.Writer, node *Node, nodeData *ListItemData, entering bool) {
if entering {
openTag := "<li>"
if nodeData.ListFlags&ListTypeDefinition != 0 {
@ -748,7 +748,7 @@ func (r *HTMLRenderer) codeBlock(w io.Writer, node *Node, nodeData *CodeBlockDat
escapeHTML(w, node.Literal)
r.outs(w, "</code>")
r.outs(w, "</pre>")
if !isItemData(node.Parent.Data) {
if !isListItemData(node.Parent.Data) {
r.cr(w)
}
}
@ -845,8 +845,8 @@ func (r *HTMLRenderer) RenderNode(w io.Writer, node *Node, entering bool) WalkSt
r.horizontalRule(w)
case *ListData:
r.list(w, node, nodeData, entering)
case *ItemData:
r.item(w, node, nodeData, entering)
case *ListItemData:
r.listItem(w, node, nodeData, entering)
case *CodeBlockData:
r.codeBlock(w, node, nodeData)
case *TableData:

View File

@ -445,7 +445,7 @@ func link(p *Parser, data []byte, offset int) (int, *Node) {
}
}
footnoteNode = NewNode(&ItemData{})
footnoteNode = NewNode(&ListItemData{})
if t == linkInlineFootnote {
// create a new reference
noteID = len(p.notes) + 1

20
node.go
View File

@ -26,8 +26,8 @@ type ListData struct {
IsFootnotesList bool // This is a list of footnotes
}
// ItemData represents data for item node
type ItemData struct {
// ListItemData represents data for list item node
type ListItemData struct {
ListFlags ListType
Tight bool // Skip <p>s around list item data if true
BulletChar byte // '*', '+' or '-' in bullet lists
@ -204,7 +204,7 @@ func (n *Node) AppendChild(child *Node) {
func (n *Node) isContainer() bool {
switch n.Data.(type) {
case *DocumentData, *BlockQuoteData, *ListData, *ItemData, *ParagraphData:
case *DocumentData, *BlockQuoteData, *ListData, *ListItemData, *ParagraphData:
return true
case *HeadingData, *EmphData, *StrongData, *DelData, *LinkData, *ImageData:
return true
@ -227,13 +227,13 @@ func isListTight(d NodeData) bool {
return false
}
func isItemData(d NodeData) bool {
_, ok := d.(*ItemData)
func isListItemData(d NodeData) bool {
_, ok := d.(*ListItemData)
return ok
}
func isItemTerm(node *Node) bool {
data, ok := node.Data.(*ItemData)
func isListItemTerm(node *Node) bool {
data, ok := node.Data.(*ListItemData)
return ok && data.ListFlags&ListTypeTerm != 0
}
@ -265,9 +265,9 @@ func isDocumentData(d NodeData) bool {
func (n *Node) canContain(v NodeData) bool {
switch n.Data.(type) {
case *ListData:
return isItemData(v)
case *DocumentData, *BlockQuoteData, *ItemData:
return !isItemData(v)
return isListItemData(v)
case *DocumentData, *BlockQuoteData, *ListItemData:
return !isListItemData(v)
case *TableData:
switch v.(type) {
case *TableHeadData, *TableBodyData:

View File

@ -288,7 +288,7 @@ func (p *Parser) parseRefsToAST() {
ref := p.notes[i]
p.addExistingChild(ref.footnote, 0)
block := ref.footnote
blockData := block.Data.(*ItemData)
blockData := block.Data.(*ListItemData)
blockData.ListFlags = flags | ListTypeOrdered
blockData.RefLink = ref.link
if ref.hasBlock {

View File

@ -6,8 +6,6 @@
[x] simplify oliPrefix()
[ ] rename item => listItem
[ ] speed: Node is probably too fat
[ ] speed: Node could be allocated from a slice and pointers could be replaces with int32 integers. Node would have to keep track of the allocator or we can change the api to pass both Parser (which is allocator of nodes) and Node (which would be a typedef for int)