Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlighting multi-line comments #2150

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
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) => {
KesterTan marked this conversation as resolved.
Show resolved Hide resolved
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, '').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/<!--|--!?>/g, ""));
Fixed Show fixed Hide fixed
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>`;
Fixed Show fixed Hide fixed
KesterTan marked this conversation as resolved.
Show resolved Hide resolved
}
});
});
PDFJS.workerSrc = "<%= asset_url 'pdf.worker.js' %>";
</script>
<%= render partial: "golden-layout" %>
Expand Down