mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-22 14:05:13 +00:00
update parser
This commit is contained in:
parent
d4e8a42128
commit
83ae6cc667
2 changed files with 22 additions and 9 deletions
|
@ -7,8 +7,8 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm run tsc && npm run peg && npm run webpack",
|
"build": "npm run tsc && npm run peg && npm run webpack",
|
||||||
"build-dev": "npm run tsc && npm run peg-dev && npm run webpack-dev",
|
"build-dev": "npm run tsc && npm run peg-dev && npm run webpack-dev",
|
||||||
"peg": "mkdirp ./built/parser && pegjs -o built/parser/core-parser.js --allowed-start-rules root,plain src/parser/core-parser.pegjs",
|
"peg": "mkdirp ./built/parser && pegjs -o built/parser/core-parser.js --allowed-start-rules rootParser,inlineParser,plainParser src/parser/core-parser.pegjs",
|
||||||
"peg-dev": "mkdirp ./built/parser && pegjs -o built/parser/core-parser.js --allowed-start-rules root,plain --trace src/parser/core-parser.pegjs",
|
"peg-dev": "mkdirp ./built/parser && pegjs -o built/parser/core-parser.js --allowed-start-rules rootParser,inlineParser,plainParser --trace src/parser/core-parser.pegjs",
|
||||||
"tsc": "tsc",
|
"tsc": "tsc",
|
||||||
"webpack": "webpack --mode=production",
|
"webpack": "webpack --mode=production",
|
||||||
"webpack-dev": "webpack --mode=development",
|
"webpack-dev": "webpack --mode=development",
|
||||||
|
|
|
@ -10,12 +10,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
root
|
rootParser
|
||||||
= ts:(block / inline)* { return mergeText(ts); }
|
= ts:(block / inline)* { return mergeText(ts); }
|
||||||
|
|
||||||
plain
|
plainParser
|
||||||
= ts:(text /*/ emoji*/)* { return mergeText(ts); }
|
= ts:(text /*/ emoji*/)* { return mergeText(ts); }
|
||||||
|
|
||||||
|
inlineParser
|
||||||
|
= ts:(inline)* { return mergeText(ts); }
|
||||||
|
|
||||||
block
|
block
|
||||||
= title
|
= title
|
||||||
/ quote
|
/ quote
|
||||||
|
@ -24,11 +27,13 @@ block
|
||||||
|
|
||||||
inline
|
inline
|
||||||
= big
|
= big
|
||||||
|
/ bold
|
||||||
/ text
|
/ text
|
||||||
|
|
||||||
text
|
text
|
||||||
= c:. { return createTree('text', { text: c }); }
|
= c:. { return createTree('text', { text: c }); }
|
||||||
|
|
||||||
|
|
||||||
// block: title
|
// block: title
|
||||||
|
|
||||||
title
|
title
|
||||||
|
@ -52,7 +57,7 @@ titleB
|
||||||
quote
|
quote
|
||||||
= lines:quote_line+
|
= lines:quote_line+
|
||||||
{
|
{
|
||||||
const children = applyParser(lines.join('\n'), 'root');
|
const children = applyParser(lines.join('\n'), 'rootParser');
|
||||||
return createTree('quote', { }, children);
|
return createTree('quote', { }, children);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,10 +89,17 @@ search_keyToken
|
||||||
// block: blockCode
|
// block: blockCode
|
||||||
|
|
||||||
blockCode
|
blockCode
|
||||||
= BEGINLINE "```" NEWLINE lines: (!("```" ENDLINE) line:blockCode_line NEWLINE { return line; } )* "```" ENDLINE { return lines; }
|
= BEGINLINE "```" lang:CHAR* NEWLINE lines:blockCode_line* "```" ENDLINE
|
||||||
|
{
|
||||||
|
lang = lang.join('');
|
||||||
|
return createTree('blockCode', {
|
||||||
|
code: lines.join('\n'),
|
||||||
|
lang: lang.length > 0 ? lang : null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
blockCode_line
|
blockCode_line
|
||||||
= (!"```" (block / inline))+
|
= !("```" ENDLINE) line:$(CHAR+) NEWLINE { return line; }
|
||||||
|
|
||||||
|
|
||||||
// inline: big
|
// inline: big
|
||||||
|
@ -110,9 +122,10 @@ bold_A
|
||||||
}
|
}
|
||||||
|
|
||||||
bold_B
|
bold_B
|
||||||
= "__" content:(!"__" i:inline { return i; })+ "__"
|
= "__" content:(!"__" i:[a-zA-Z0-9 \t] { return i; })+ "__"
|
||||||
{
|
{
|
||||||
return createTree('bold', { }, mergeText(content));
|
const parsedContent = applyParser(content.join(''), 'inlineParser');
|
||||||
|
return createTree('bold', { }, parsedContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue