Explorar el Código

ol/ul/li investigations and comments

Ivan Asmer hace 2 años
padre
commit
6fe405a040
Se han modificado 1 ficheros con 6 adiciones y 6 borrados
  1. 6 6
      index.mjs

+ 6 - 6
index.mjs

@@ -573,11 +573,11 @@ function buildAST(md, mdTags=syntax, offset=0, tree={tag: 'root'}, stack=[]){
     let {indent, childName, title, recursive, regexp, endRegexp, content: {end: {offset: offsetEnd, point} }, forward } = mdTags[currentNode.tag]
 
     if (indent){
-        if (currentNode.parent.tag !== currentNode.tag){ //li
-            let { parent: {children: siblings} } = currentNode
-            if (siblings.length > 1 && siblings.last(-2).tag === currentNode.tag){
-                siblings.pop()
-                currentNode = siblings.last()
+        if (currentNode.parent.tag !== currentNode.tag){ 
+            let { parent: {children: siblings} } = currentNode //current node are ol/ul
+            if (siblings.length > 1 && siblings.last(-2).tag === currentNode.tag){ //two ol/ul one after another should be concated as li
+                siblings.pop() //so remove last ol/ul
+                currentNode = siblings.last() //make previous ol/ul currentNode
             }
             const { children }     = currentNode
             const indentLength = currentNode.startMatch[1].length
@@ -590,7 +590,7 @@ function buildAST(md, mdTags=syntax, offset=0, tree={tag: 'root'}, stack=[]){
             let listMD   = md.slice(offset, endMatch.index + offset).cutIndent(currentNode.startMatch[0].length -2)
 
             const newNode = {tag: childName, startOffset: offset, parent: currentNode, startMatch: currentNode.startMatch}
-            children.push(newNode)
+            children.push(newNode) //create LI and add it into children of ol/ul
 
             newNode.children = buildAST(listMD, mdTags).children
             newNode.children.forEach(item => ((typeof item === 'object') &&  (item.parent = currentNode)))