feat: update marked parsers (#260)

* chore: remove external match functions

* chore: update parsers
This commit is contained in:
boojack
2022-10-04 10:44:16 +08:00
committed by GitHub
parent 4bd373ba57
commit eaf89aa2f2
18 changed files with 92 additions and 177 deletions

View File

@ -1,15 +1,5 @@
export const CODE_BLOCK_REG = /^```(\S*?)\s([\s\S]*?)```(\n?)/;
const match = (rawStr: string): number => {
const matchResult = rawStr.match(CODE_BLOCK_REG);
if (!matchResult) {
return 0;
}
const matchStr = matchResult[0];
return matchStr.length;
};
const renderer = (rawStr: string): string => {
const parsedStr = rawStr.replace(CODE_BLOCK_REG, "<pre lang='$1'>\n$2</pre>$3");
return parsedStr;
@ -18,6 +8,5 @@ const renderer = (rawStr: string): string => {
export default {
name: "code block",
regex: CODE_BLOCK_REG,
match,
renderer,
};