Skip to content

Commit

Permalink
Highlighting multi-line comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KesterTan committed Apr 22, 2024
1 parent 8511d3e commit 90bc370
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/views/submissions/view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@
var headerPositionStr = null;
<% end %>
hljs.initHighlightingOnLoad();
document.addEventListener('DOMContentLoaded', (event) => {
let combinedCode = '';
document.querySelectorAll('pre code').forEach((block) => {
combinedCode += block.textContent + '\n';
});

let highlightedCode = hljs.highlightAuto(combinedCode).value;
let commentSpans = highlightedCode.match(/<span class="hljs-comment">([^<]*)<\/span>/g);
let commentContents = commentSpans.map(span => span.replace(/<[^>]+>/g, ''));

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High

This string may still contain
<script
, which may cause an HTML element injection vulnerability.
let splitContent = commentContents.flatMap(str => str.split('\n'));

document.querySelectorAll('pre code').forEach((block, index) => {
if (block.textContent !== null && block.textContent !== "" && splitContent.includes(block.textContent.replace(/\n/g, ''))) {
block.innerHTML = `<code class='hljs-comment'>${block.textContent}</code>`;

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
}
});
});
PDFJS.workerSrc = "<%= asset_url 'pdf.worker.js' %>";
</script>
<%= render partial: "golden-layout" %>
Expand Down

0 comments on commit 90bc370

Please sign in to comment.