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

regexp indent fixes

Ivan Asmer 3 éve
szülő
commit
87bd788a64
1 módosított fájl, 39 hozzáadás és 5 törlés
  1. 39 5
      index.js

+ 39 - 5
index.js

@@ -4,6 +4,34 @@
 
 
 const syntax = {
+    a:{
+        paired: true,
+        recursive: false,
+        startRegexp: /\[(.*)\]\(/,
+        endRegexp: /\)/,
+        content: {
+            start: {
+                point: 'end',
+                offset: 0
+            },
+            end: {
+                point: 'start',
+                offset: -1
+            }
+        },
+        begin: 0,
+        forward: {
+            point: 'end', //start, startEnd, end, endEnd
+            offset: 1
+        },
+        title: {
+            //index: 1,
+            recursive: true,
+        },
+        onbuild(md, mdTags, buildAST){ //this = {tag: }
+
+        }
+    },
     strike: {
         paired: true,
         recursive: true,
@@ -25,7 +53,7 @@ const syntax = {
             offset: -1
         }
     },
-    bold: {
+    bold1: {
         paired: true,
         recursive: true,
         startRegexp: /\*\*\S.*/,
@@ -67,7 +95,7 @@ const syntax = {
             offset: -1
         }
     },
-    italic: {
+    italic1: {
         paired: true,
         recursive: true,
         startRegexp: /\*\S.*/,
@@ -416,8 +444,8 @@ const syntax = {
     }
 }
 
-const indentRegexp = (regexp,count) => new RegExp(`\\n(\\s${count === undefined ? '*' : `{${count}}` })` + regexp.toString().slice(1,-1))
-const indentEndRegexp = (count) => new RegExp(`\\n(\\s${count === undefined ? '*' : `{0,${count}}` })\\S`)
+const indentRegexp = (regexp,count) => new RegExp(`\\n([ \\t]${count === undefined ? '*' : `{${count}}` })` + regexp.toString().slice(1,-1))
+const indentEndRegexp = (count) => new RegExp(`\\n([ \\t]${count === undefined ? '*' : `{0,${count}}` })\\S`)
 
 function findNearest(md, mdTags, offset=0){
     let nearest, nearestMatch = {index: Infinity};
@@ -482,7 +510,7 @@ function buildAST(md, mdTags=syntax, offset=0, tree={tag: 'root'}, stack=[]){
             endRegexp = indentEndRegexp(indentLength)
             let endMatch = md.offsetMatch(offset, endRegexp) || {index: md.length +1, 0: 'zzz'}
 
-            let listMD   = md.slice(offset, endMatch.index + offset).cutIndent(currentNode.startMatch[0].length -1)
+            let listMD   = md.slice(offset, endMatch.index + offset).cutIndent(currentNode.startMatch[0].length -2)
             debugger;
 
             const newNode = {tag: childName, startOffset: offset, parent: currentNode, startMatch: currentNode.startMatch}
@@ -552,6 +580,11 @@ const Heading = ({react:React, children, title, node: {tag}}) => {
             )
 }
 
+const A = ({react:React, children, title}) =>{
+    const _ = React.createElement.bind(React)
+    return _("a", {children: title, href: children})
+}
+
 const defaultMapMDToComponents = {
     heading1: Heading,
     heading2: Heading,
@@ -562,6 +595,7 @@ const defaultMapMDToComponents = {
     strike: "strike",
     bold1: "strong",
     bold2: "strong",
+    a: A, 
     italic1: "i",
     italic2: "i",
     unOrderedList: 'ul',