|
@@ -7,18 +7,19 @@ const syntax = {
|
|
|
bold: {
|
|
|
paired: true,
|
|
|
recursive: true,
|
|
|
- startRegexp: /\s\*\*\S.*/,
|
|
|
+ startRegexp: /\*\*\S.*/,
|
|
|
endRegexp: /\S\*\*\s/,
|
|
|
content: {
|
|
|
start: {
|
|
|
point: 'start',
|
|
|
- offset: 3
|
|
|
+ offset: 2
|
|
|
},
|
|
|
end: {
|
|
|
point: 'end',
|
|
|
offset: 1
|
|
|
}
|
|
|
},
|
|
|
+ begin: 0,
|
|
|
forward: {
|
|
|
point: 'endEnd', //start, startEnd, end, endEnd
|
|
|
offset: -1
|
|
@@ -27,7 +28,7 @@ const syntax = {
|
|
|
bold2: {
|
|
|
paired: true,
|
|
|
recursive: true,
|
|
|
- startRegexp: /__\S.*/,
|
|
|
+ startRegexp: /\s__\S.*/,
|
|
|
endRegexp: /\S__\s/,
|
|
|
content: {
|
|
|
start: {
|
|
@@ -39,6 +40,7 @@ const syntax = {
|
|
|
offset: 1
|
|
|
}
|
|
|
},
|
|
|
+ begin: 1,
|
|
|
forward: {
|
|
|
point: 'endEnd', //start, startEnd, end, endEnd
|
|
|
offset: -1
|
|
@@ -47,7 +49,7 @@ const syntax = {
|
|
|
italic: {
|
|
|
paired: true,
|
|
|
recursive: true,
|
|
|
- startRegexp: /\s\*\S.*/,
|
|
|
+ startRegexp: /\*\S.*/,
|
|
|
endRegexp: /\S\*\s/,
|
|
|
content: {
|
|
|
start: {
|
|
@@ -59,6 +61,7 @@ const syntax = {
|
|
|
offset: 1
|
|
|
}
|
|
|
},
|
|
|
+ begin: 0,
|
|
|
forward: {
|
|
|
point: 'endEnd', //start, startEnd, end, endEnd
|
|
|
offset: -1
|
|
@@ -67,7 +70,7 @@ const syntax = {
|
|
|
italic2: {
|
|
|
paired: true,
|
|
|
recursive: true,
|
|
|
- startRegexp: /_\S.*/,
|
|
|
+ startRegexp: /\s_\S.*/,
|
|
|
endRegexp: /\S_\s/,
|
|
|
content: {
|
|
|
start: {
|
|
@@ -79,6 +82,7 @@ const syntax = {
|
|
|
offset: 1
|
|
|
}
|
|
|
},
|
|
|
+ begin: 1,
|
|
|
forward: {
|
|
|
point: 'endEnd', //start, startEnd, end, endEnd
|
|
|
offset: -1
|
|
@@ -89,14 +93,10 @@ const syntax = {
|
|
|
function findNearest(md, mdTags){
|
|
|
let nearest, nearestMatch = {index: Infinity};
|
|
|
for (let [mdTag, {paired,
|
|
|
- recursive,
|
|
|
startRegexp,
|
|
|
- endRegexp,
|
|
|
- content: {start,
|
|
|
- end},
|
|
|
- forward}] of Object.entries(mdTags)) {
|
|
|
+ rexexp}] of Object.entries(mdTags)) {
|
|
|
|
|
|
- let match = md.match(startRegexp)
|
|
|
+ let match = md.match(startRegexp || regexp)
|
|
|
if (match && match.index < nearestMatch.index){
|
|
|
nearestMatch = match
|
|
|
nearest = mdTag
|
|
@@ -105,10 +105,35 @@ function findNearest(md, mdTags){
|
|
|
return [nearest, nearestMatch]
|
|
|
}
|
|
|
|
|
|
+function cutNode(md, match, tagName, {paired, recursive, startRegexp, endRegexp, content: {start, end}, begin, forward}){
|
|
|
+ //if (paired){
|
|
|
+ //md.match()
|
|
|
+ //}
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
function buildAST(md, mdTags=syntax, tree=[], path=[]){
|
|
|
- console.log(findNearest(md, mdTags))
|
|
|
+ const result = []
|
|
|
+ while(md){
|
|
|
+ const [nearest, nearestMatch] = findNearest(md, mdTags)
|
|
|
+ if (nearest){
|
|
|
+ const {begin} = mdTags[nearest]
|
|
|
+ if (nearestMatch.index){
|
|
|
+ result.push(md.slice(0, nearestMatch.index + begin))
|
|
|
+ md = md.slice(nearestMatch.index)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.log(nearestMatch)
|
|
|
+ break //to avoid infinite loop, add cutNode here
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ result.push(md)
|
|
|
+ md = ''
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result
|
|
|
}
|
|
|
|
|
|
-buildAST("I just __love__ __bold text__. ")
|
|
|
+console.log(buildAST("I just __love__ __bold text__. "))
|
|
|
|