-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Use a web worker for syntax highlighting, drop IE11 support #7727
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
Conversation
Syntax highlighting is now done in a separate thread which should help performance on large files. The web worker is initialized from a function which is not something IE11 supports and which would force us to create a separate .js file for the worker code. For the reason above, I think it's a good opportunity to end IE11 support with this commit, so it should be landed in the next minor release version. The code uses various ES2017 features and should work in all evergreen browsers. Fixes: go-gitea#6147
f8a32ab
to
ababfbf
Compare
Codecov Report
@@ Coverage Diff @@
## master #7727 +/- ##
==========================================
- Coverage 41.29% 41.29% -0.01%
==========================================
Files 472 472
Lines 63833 63833
==========================================
- Hits 26363 26360 -3
- Misses 34032 34034 +2
- Partials 3438 3439 +1
Continue to review full report at Codecov.
|
if (node.querySelector("ol.linenums")) { | ||
const lines = result.split(/\r?\n/).map((line, i) => `<li class="L${i + 1}" rel="L${i + 1}">${line}</li>`); | ||
node.classList.add("hljs"); | ||
node.innerHTML = `<ol class="linenums">${lines.join("")}<ol>`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ol.linenums
business seems to only be present in rendered files to support adding the yellow background on linked lines. Not happy having to do this wrapping here at all. I think future improvement would be to eliminate these children of pre > code
so they would contain only text nodes and that the output of the highlighter can be rendered as-is in all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related: highlightjs/highlight.js#2086
There is a regression in multi-line highlights: > hljs.highlightAuto("`a\nb`", ["javascript"]).value
"<span class=\"hljs-string\">`a
b`</span>" Essentially |
Actually, I think I'll have to give up on this for now. Reasons being:
Generally, I think syntax highlighting should be performed server-side. |
Syntax highlighting is now done in a separate thread which should help performance on large files.
The web worker is initialized from a function which is not something IE11 supports and which would force us to create a separate .js file for the worker code.
For the reason above, I think it's a good opportunity to end IE11 support with this commit, so it should be landed in the next minor release version.
The code uses various ES2017 features. It should work in all evergreen browsers.
Fixes: #6147