Files
memos/web/src/labs/marked/parser/Emphasis.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

23 lines
498 B
TypeScript

import { marked } from "..";
import { matcher } from "../matcher";
import Link from "./Link";
import PlainText from "./PlainText";
export const EMPHASIS_REG = /\*(.+?)\*/;
const renderer = (rawStr: string) => {
const matchResult = matcher(rawStr, EMPHASIS_REG);
if (!matchResult) {
return rawStr;
}
const parsedContent = marked(matchResult[1], [], [Link, PlainText]);
return <em>{parsedContent}</em>;
};
export default {
name: "emphasis",
regexp: EMPHASIS_REG,
renderer,
};