memos/web/src/labs/marked/parser/InlineCode.tsx
boojack 0f8ce3dd16
refactor: return jsx element instead of string in marked (#910)
* refactor: return jsx element instead of string in marked

* chore: update
2023-01-07 00:13:49 +08:00

19 lines
393 B
TypeScript

import { escape } from "lodash-es";
import { matcher } from "../matcher";
export const INLINE_CODE_REG = /`(.+?)`/;
const renderer = (rawStr: string) => {
const matchResult = matcher(rawStr, INLINE_CODE_REG);
if (!matchResult) {
return rawStr;
}
return <code>{escape(matchResult[1])}</code>;
};
export default {
name: "inline code",
regexp: INLINE_CODE_REG,
renderer,
};