From 55ffc5cd594cf5a8b71b38009429094717358540 Mon Sep 17 00:00:00 2001
From: Krzysztof Kowalczyk
Date: Fri, 26 Jan 2018 22:23:27 -0800
Subject: [PATCH] rename item => listItem
---
block.go | 4 ++--
html_renderer.go | 20 ++++++++++----------
inline.go | 2 +-
node.go | 20 ++++++++++----------
parser.go | 2 +-
todo.md | 2 --
6 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/block.go b/block.go
index 3af89a6..c81e2d9 100644
--- a/block.go
+++ b/block.go
@@ -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,
diff --git a/html_renderer.go b/html_renderer.go
index 352a945..d7d5fe4 100644
--- a/html_renderer.go
+++ b/html_renderer.go
@@ -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("
"))
- if !(isItemData(node.Parent.Data) && node.Next == nil) {
+ r.outs(w, "")
+ 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 := ""
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, "")
r.outs(w, "")
- 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:
diff --git a/inline.go b/inline.go
index 88c0f6e..a142994 100644
--- a/inline.go
+++ b/inline.go
@@ -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
diff --git a/node.go b/node.go
index 63053cf..dba3dc2 100644
--- a/node.go
+++ b/node.go
@@ -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 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:
diff --git a/parser.go b/parser.go
index c438c72..af9c9fb 100644
--- a/parser.go
+++ b/parser.go
@@ -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 {
diff --git a/todo.md b/todo.md
index eb92126..77ad59f 100644
--- a/todo.md
+++ b/todo.md
@@ -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)