mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: simple markdown parser (#252)
* feat: simple markdown parser * chore: rename test file name * feat: add plain text link parser * chore: update style
This commit is contained in:
23
web/src/labs/marked/parser/CodeBlock.ts
Normal file
23
web/src/labs/marked/parser/CodeBlock.ts
Normal file
@ -0,0 +1,23 @@
|
||||
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;
|
||||
};
|
||||
|
||||
export default {
|
||||
name: "code block",
|
||||
regex: CODE_BLOCK_REG,
|
||||
match,
|
||||
renderer,
|
||||
};
|
Reference in New Issue
Block a user