Forráskód Böngészése

+orderedList, +headings2..6

Ivan Asmer 4 éve
szülő
commit
8e36eefeee
1 módosított fájl, 173 hozzáadás és 4 törlés
  1. 173 4
      index.js

+ 173 - 4
index.js

@@ -109,22 +109,168 @@ const syntax = {
             offset: -1
         }
     },
+
+
+    heading6: {
+        paired: true,
+        recursive: true,
+        startRegexp: /\n######[ \t]*(.*)\n/,
+        endRegexp: /\n#\s/,
+        content: {
+            start: {
+                point: 'end',
+                offset: -1
+            },
+            end: {
+                point: 'start',
+                offset: 0
+            }
+        },
+        begin: 0,
+        forward: {
+            point: 'end', //start, startEnd, end, endEnd
+            offset: 0
+        },
+        title: {
+            //index: 1,
+            recursive: true,
+        },
+        onbuild(md, mdTags, buildAST){ //this = {tag: }
+
+        }
+    },
+    heading5: {
+        paired: true,
+        recursive: true,
+        startRegexp: /\n#####[ \t]*(.*)\n/,
+        endRegexp: /\n#{1,5}\s/,
+        content: {
+            start: {
+                point: 'end',
+                offset: -1
+            },
+            end: {
+                point: 'start',
+                offset: 0
+            }
+        },
+        begin: 0,
+        forward: {
+            point: 'end', //start, startEnd, end, endEnd
+            offset: 0
+        },
+        title: {
+            //index: 1,
+            recursive: true,
+        },
+        onbuild(md, mdTags, buildAST){ //this = {tag: }
+
+        }
+    },
+
+    heading4: {
+        paired: true,
+        recursive: true,
+        startRegexp: /\n####[ \t]*(.*)\n/,
+        endRegexp: /\n#{1,4}\s/,
+        content: {
+            start: {
+                point: 'end',
+                offset: -1
+            },
+            end: {
+                point: 'start',
+                offset: 0
+            }
+        },
+        begin: 0,
+        forward: {
+            point: 'end', //start, startEnd, end, endEnd
+            offset: 0
+        },
+        title: {
+            //index: 1,
+            recursive: true,
+        },
+        onbuild(md, mdTags, buildAST){ //this = {tag: }
+
+        }
+    },
+
+    heading3: {
+        paired: true,
+        recursive: true,
+        startRegexp: /\n###[ \t]*(.*)\n/,
+        endRegexp: /\n#{1,3}\s/,
+        content: {
+            start: {
+                point: 'end',
+                offset: -1
+            },
+            end: {
+                point: 'start',
+                offset: 0
+            }
+        },
+        begin: 0,
+        forward: {
+            point: 'end', //start, startEnd, end, endEnd
+            offset: 0
+        },
+        title: {
+            //index: 1,
+            recursive: true,
+        },
+        onbuild(md, mdTags, buildAST){ //this = {tag: }
+
+        }
+    },
+
+    heading2: {
+        paired: true,
+        recursive: true,
+        startRegexp: /\n##[ \t]*(.*)\n/,
+        endRegexp: /\n#{1,2}\s/,
+        content: {
+            start: {
+                point: 'end',
+                offset: -1
+            },
+            end: {
+                point: 'start',
+                offset: 0
+            }
+        },
+        begin: 0,
+        forward: {
+            point: 'end', //start, startEnd, end, endEnd
+            offset: 0
+        },
+        title: {
+            //index: 1,
+            recursive: true,
+        },
+        onbuild(md, mdTags, buildAST){ //this = {tag: }
+
+        }
+    },
+
     heading1: {
         paired: true,
         recursive: true,
         startRegexp: /\n#[ \t]*(.*)\n/,
-        endRegexp: /\n#/,
+        endRegexp: /\n#\s/,
         content: {
             start: {
                 point: 'end',
-                offset: 0
+                offset: -1
             },
             end: {
                 point: 'start',
                 offset: 0
             }
         },
-        begin: 1,
+        begin: -1,
         forward: {
             point: 'end', //start, startEnd, end, endEnd
             offset: 0
@@ -224,6 +370,29 @@ const syntax = {
             point: 'end',
             offset: 0
         }
+    },
+
+    orderedList: {
+        indent: true,
+        childName: 'orderedListItem',
+        //paired: true,
+        recursive: true,
+        regexp: /\d+\.\s*\S/,
+        content:{
+            start:{
+                point: 'end',
+                offset: -1
+            },
+            end:{
+                point: 'start',
+                offset: 0
+            }
+        },
+        begin: 1,
+        forward:  {
+            point: 'end',
+            offset: 0
+        }
     }
 }
 
@@ -287,6 +456,7 @@ function buildAST(md, mdTags=syntax, offset=0, tree={tag: 'root'}, stack=[]){
             }
             const { children }     = currentNode
             const indentLength = currentNode.startMatch[1].length
+            console.log(indentLength)
             currentNode.indentLength = indentLength
 
             endRegexp = indentEndRegexp(indentLength)
@@ -325,7 +495,6 @@ function buildAST(md, mdTags=syntax, offset=0, tree={tag: 'root'}, stack=[]){
                 currentNode.endContent = offset + endMatch.index + offsetEnd + (point === 'end' ? endMatch[0].length : 0)
                 offset !== currentNode.endContent && children.push(md.slice(offset, currentNode.endContent))
                 offset += endMatch.index + forward.offset + (forward.point === 'endEnd' ? endMatch[0].length : 0)
-                console.log(currentNode.tag, forward.point === 'endEnd' ? endMatch[0].length : 0)
                 currentNode.endOffset = offset
                 currentNode.endMatch  = endMatch
                 return currentNode