memos/web/src/labs/marked/parser/CodeBlock.ts
boojack eaf89aa2f2
feat: update marked parsers (#260)
* chore: remove external match functions

* chore: update parsers
2022-10-04 10:44:16 +08:00

12 lines
298 B
TypeScript

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;
};
export default {
name: "code block",
regex: CODE_BLOCK_REG,
renderer,
};