Skip to content
Snippets Groups Projects
Commit 7d65a7eb 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 4d5be0b4
No related branches found
No related tags found
1 merge request!234Add highlight syntax to code blocks in blog posts
...@@ -121,7 +121,10 @@ class MarkdownViewer extends Component { ...@@ -121,7 +121,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 // 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; const noImageActive = cleanText.indexOf(noImageText) !== -1;
......
...@@ -147,10 +147,16 @@ function traverseForCodeHighlight(node, depth = 0) { ...@@ -147,10 +147,16 @@ function traverseForCodeHighlight(node, depth = 0) {
} }
export function highlightCodes(html) { export function highlightCodes(html) {
const doc = DOMParser.parseFromString(html, 'text/html'); if (html.match(/<code>.*?<\/code>/s)) {
traverseForCodeHighlight(doc); const doc = DOMParser.parseFromString(html, 'text/html');
traverseForCodeHighlight(doc);
return {
html: doc ? XMLSerializer.serializeToString(doc) : '',
};
}
return { 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