diff --git a/src/utils/markdown.ts b/src/utils/markdown.ts new file mode 100644 index 0000000..a845bd4 --- /dev/null +++ b/src/utils/markdown.ts @@ -0,0 +1,19 @@ +import { marked } from 'marked' + +marked.setOptions({ + breaks: true, + gfm: true, +}) + +export function renderMarkdown(text: string): string { + if (!text) return '' + return marked.parseInline(text) as string +} + +export function stripMarkdown(text: string): string { + if (!text) return '' + return text + .replace(/[*_~`#]/g, '') + .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') + .replace(/!\[([^\]]*)\]\([^)]+\)/g, '$1') +}