Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/lib/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-ignore
import MarkdownIt from 'markdown-it';
import MarkdownItAsync from 'markdown-it-async';
import sanitizeHtml from 'sanitize-html';

// replaces @variableName@ with the value of the variable
export function replaceVariables(
Expand Down Expand Up @@ -87,7 +88,15 @@ export async function markdownToHtmlWithHighlighting(markdown: string) {
return defaultRender(tokens, idx, options, env, self);
};

return markdownItAsync.renderAsync(replaceVariables(markdown));
const rawHtml = await markdownItAsync.renderAsync(replaceVariables(markdown));
return sanitizeHtml(rawHtml, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['span', 'img']),
allowedAttributes: {
...sanitizeHtml.defaults.allowedAttributes,
'*': ['class', 'style'],
a: ['href', 'name', 'target', 'rel'],
},
});

} catch (e) {
return markdown;
Expand Down