feat: add escape to renderer

This commit is contained in:
steven
2022-10-04 13:53:36 +08:00
parent ea911387f1
commit 486cf8bdac
11 changed files with 80 additions and 17 deletions

View File

@ -1,8 +1,14 @@
import { escape } from "lodash-es";
export const CODE_BLOCK_REG = /^```(\S*?)\s([\s\S]*?)```(\n?)/;
const renderer = (rawStr: string): string => {
const parsedStr = rawStr.replace(CODE_BLOCK_REG, "<pre lang='$1'>\n$2</pre>$3");
return parsedStr;
const matchResult = rawStr.match(CODE_BLOCK_REG);
if (!matchResult) {
return rawStr;
}
return `<pre lang='${escape(matchResult[1])}'>\n${escape(matchResult[2])}</pre>${matchResult[3]}`;
};
export default {