Release 0.3.0
This commit is contained in:
1 parent
08e8875cb5
commit
7590be66a5
31 files changed
+3270
-151
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { marked } from 'marked';
|
||||
import sanitizeHtml from 'sanitize-html';
|
||||
|
||||
export function renderMarkdown(markdown: string): string {
|
||||
const rendered = marked.parse(markdown, {
|
||||
async: false,
|
||||
breaks: true,
|
||||
gfm: true
|
||||
}) as string;
|
||||
return sanitizeHtml(rendered, {
|
||||
allowedTags: [
|
||||
'p',
|
||||
'br',
|
||||
'strong',
|
||||
'em',
|
||||
'del',
|
||||
'blockquote',
|
||||
'ul',
|
||||
'ol',
|
||||
'li',
|
||||
'h2',
|
||||
'h3',
|
||||
'h4',
|
||||
'code',
|
||||
'pre',
|
||||
'a',
|
||||
'hr'
|
||||
],
|
||||
allowedAttributes: {
|
||||
a: ['href', 'title', 'target', 'rel']
|
||||
},
|
||||
allowedSchemes: ['http', 'https', 'mailto'],
|
||||
allowProtocolRelative: false,
|
||||
enforceHtmlBoundary: true,
|
||||
transformTags: {
|
||||
a: (_tagName, attributes) => ({
|
||||
tagName: 'a',
|
||||
attribs: { ...attributes, target: '_blank', rel: 'noopener noreferrer' }
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user