|
@@ -8,7 +8,7 @@ const syntax = {
|
|
|
paired: true,
|
|
|
recursive: true,
|
|
|
startRegexp: /\*\*\S.*/,
|
|
|
- endRegexp: /\S\*\*\s/,
|
|
|
+ endRegexp: /\S\*\*\W/,
|
|
|
content: {
|
|
|
start: {
|
|
|
point: 'start',
|
|
@@ -109,6 +109,27 @@ const syntax = {
|
|
|
offset: -1
|
|
|
}
|
|
|
},
|
|
|
+ heading1: {
|
|
|
+ paired: true,
|
|
|
+ recursive: true,
|
|
|
+ startRegexp: /\n#[ \t]*(.*)\n/,
|
|
|
+ endRegexp: /\n#/,
|
|
|
+ content: {
|
|
|
+ start: {
|
|
|
+ point: 'end',
|
|
|
+ offset: 1
|
|
|
+ },
|
|
|
+ end: {
|
|
|
+ point: 'start',
|
|
|
+ offset: 0
|
|
|
+ }
|
|
|
+ },
|
|
|
+ begin: 1,
|
|
|
+ forward: {
|
|
|
+ point: 'endEnd', //start, startEnd, end, endEnd
|
|
|
+ offset: -1
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function findNearest(md, mdTags, offset=0){
|
|
@@ -160,12 +181,11 @@ function buildAST(md, mdTags=syntax, offset=0, tree={tag: 'root'}, stack=[]){
|
|
|
const [nearest, nearestMatch] = findNearest(md, mdTags, offset)
|
|
|
const endMatch = md.offsetMatch(offset, endRegexp)
|
|
|
if (endMatch) {
|
|
|
- if (!nearest || endMatch.index < nearestMatch.index){
|
|
|
+ if (!nearest || endMatch.index <= nearestMatch.index){
|
|
|
currentNode.endContent = offset + endMatch.index + offsetEnd
|
|
|
children.push(md.slice(offset, currentNode.endContent))
|
|
|
offset += endMatch.index + endMatch[0].length + forward.offset
|
|
|
currentNode.endOffset = offset
|
|
|
- console.log('endmatch current', currentNode)
|
|
|
return currentNode
|
|
|
}
|
|
|
}
|
|
@@ -174,24 +194,22 @@ function buildAST(md, mdTags=syntax, offset=0, tree={tag: 'root'}, stack=[]){
|
|
|
if (nearestMatch.index){
|
|
|
children.push(md.slice(offset, offset + nearestMatch.index + begin))
|
|
|
offset += nearestMatch.index
|
|
|
- console.log(offset, md.slice(offset))
|
|
|
}
|
|
|
else {
|
|
|
const newNode = {tag: nearest, startOffset: offset, parent: currentNode}
|
|
|
children.push(newNode)
|
|
|
buildAST(md, mdTags, offset + start.offset, tree, [...stack, newNode])
|
|
|
- console.log('same', newNode)
|
|
|
offset = newNode.endOffset
|
|
|
- console.log(offset, md.slice(offset))
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
- children.push(md)
|
|
|
- md = ''
|
|
|
+ children.push(md.slice(offset))
|
|
|
+ offset = md.length
|
|
|
}
|
|
|
}
|
|
|
return currentNode
|
|
|
}
|
|
|
|
|
|
-console.log(buildAST("I just **love _bold text_ adddd** hahaha").children[1])
|
|
|
+debugger;
|
|
|
+console.log(buildAST("I just **love _bold text_ adddd**. hahaha").children[1])
|
|
|
|