feat: add markdown rendering for entry descriptions
This commit is contained in:
19
src/utils/markdown.ts
Normal file
19
src/utils/markdown.ts
Normal file
@@ -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')
|
||||
}
|
||||
Reference in New Issue
Block a user