computer-scienceangular-roadmapbackend-roadmapblockchain-roadmapdba-roadmapdeveloper-roadmapdevops-roadmapfrontend-roadmapgo-roadmaphactoberfestjava-roadmapjavascript-roadmapnodejs-roadmappython-roadmapqa-roadmapreact-roadmaproadmapstudy-planvue-roadmapweb3-roadmap
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
697 B
26 lines
697 B
// @ts-ignore |
|
import MarkdownIt from 'markdown-it'; |
|
|
|
export function markdownToHtml(markdown: string, isInline = true): string { |
|
try { |
|
const md = new MarkdownIt({ |
|
html: true, |
|
linkify: true, |
|
}); |
|
|
|
if (isInline) { |
|
return md.renderInline(markdown); |
|
} else { |
|
return md.render(markdown); |
|
} |
|
} catch (e) { |
|
return markdown; |
|
} |
|
} |
|
|
|
// This is a workaround for the issue with tiptap-markdown extension |
|
// It doesn't support links with escaped brackets like this: |
|
// \\[link\\](https://example.com) -> [link](https://example.com) |
|
export function sanitizeMarkdown(markdown: string) { |
|
return markdown.replace(/\\\[([^\\]+)\\\]\(([^\\]+)\)/g, '[$1]($2)'); |
|
}
|
|
|