Skip to content
Snippets Groups Projects
Commit c793efd8 authored by Quoc Huy Nguyen Dinh's avatar Quoc Huy Nguyen Dinh
Browse files

Fix bug crashing the page when adding <script> tag only in the post editor

parent bc2ed84d
No related branches found
No related tags found
2 merge requests!343- gray out negative rshares comment and don't render the markdown,!341Resolve "Consider adding highlights for code blocks"
......@@ -123,7 +123,10 @@ class MarkdownViewer extends Component {
}
// Needs to be done here so that the tags added by HighlightJS won't be filtered of by the sanitizer
cleanText = highlightCodes(cleanText).html;
const higlightedText = highlightCodes(cleanText).html;
if (higlightedText) {
cleanText = higlightedText;
}
const noImageActive = cleanText.indexOf(noImageText) !== -1;
......
......@@ -146,10 +146,16 @@ function traverseForCodeHighlight(node, depth = 0) {
}
export function highlightCodes(html) {
const doc = DOMParser.parseFromString(html, 'text/html');
traverseForCodeHighlight(doc);
if (html.match(/<code>.*?<\/code>/s)) {
const doc = DOMParser.parseFromString(html, 'text/html');
traverseForCodeHighlight(doc);
return {
html: doc ? XMLSerializer.serializeToString(doc) : '',
};
}
return {
html: doc ? XMLSerializer.serializeToString(doc) : '',
html: null,
};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment