Ivan Asmer 4 лет назад
Родитель
Сommit
adf0fc91f3
1 измененных файлов с 77 добавлено и 5 удалено
  1. 77 5
      index.js

+ 77 - 5
index.js

@@ -130,7 +130,7 @@ const syntax = {
             offset: 0
         },
         title: {
-            index: 1,
+            //index: 1,
             recursive: true,
         },
         onbuild(md, mdTags, buildAST){ //this = {tag: }
@@ -157,6 +157,73 @@ const syntax = {
             point: 'end', //start, startEnd, end, endEnd
             offset: 1
         }
+    },
+    codeMultiLine: {
+        paired: true, 
+        recursive: false,
+        startRegexp: /\n```\s*\n/,
+        endRegexp: /\n```\s*\n/,
+        content:{
+            start:{
+                point: 'end',
+                offset: 0
+            },
+            end:{
+                point: 'start',
+                offset: 0
+            }
+        },
+        begin: 1,
+        forward:  {
+            point: 'endEnd',
+            offset: 0
+        },
+    },
+    codeLanguage: {
+        paired: true, 
+        recursive: false,
+        startRegexp: /\n```(\w+)\s*\n/,
+        endRegexp: /\n```\s*\n/,
+        title: {
+            recursive: false
+        },
+        content:{
+            start:{
+                point: 'end',
+                offset: 0
+            },
+            end:{
+                point: 'start',
+                offset: 0
+            }
+        },
+        begin: 1,
+        forward:  {
+            point: 'endEnd',
+            offset: 0
+        },
+    },
+    unOrderedList: {
+        indent: true,
+        childName: 'unOrderedListItem',
+        //paired: true,
+        recursive: true,
+        regexp: /\n(\s*)-\s*/,
+        content:{
+            start:{
+                point: 'end',
+                offset: 0
+            },
+            end:{
+                point: 'start',
+                offset: 0
+            }
+        },
+        begin: 1,
+        forward:  {
+            point: 'end',
+            offset: -1
+        }
     }
 }
 
@@ -164,7 +231,7 @@ function findNearest(md, mdTags, offset=0){
     let nearest, nearestMatch = {index: Infinity};
     for (let [mdTag, {paired, 
                         startRegexp, 
-                        rexexp}] of  Object.entries(mdTags)) {
+                        regexp}] of  Object.entries(mdTags)) {
         if (mdTag === 'root') continue;
 
         let match = md.offsetMatch(offset, startRegexp || regexp)
@@ -198,13 +265,18 @@ function buildAST(md, mdTags=syntax, offset=0, tree={tag: 'root'}, stack=[]){
     currentNode.children  = currentNode.children || []
     const { children }     = currentNode
 
-    const {title, recursive, endRegexp, content: {end: {offset: offsetEnd, point} }, forward } = mdTags[currentNode.tag]
+    const {indent, title, recursive, endRegexp, content: {end: {offset: offsetEnd, point} }, forward } = mdTags[currentNode.tag]
+
+    if (indent){
+        debugger;
+    }
     
     if (title){
-        const {index, recursive} = title
+        const {index=1, recursive} = title
         const {[index]: titleContent } = currentNode.startMatch
-        if (recursive){
+        if (titleContent && recursive){
             currentNode.title = buildAST(titleContent, mdTags).children
+            currentNode.title.forEach(item => item.parent = currentNode)
         }
         else {
             currentNode.title = [titleContent]