-
Notifications
You must be signed in to change notification settings - Fork 338
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
Lazy loading less common languages for syntax highlighting #2388
Conversation
Reduces client.js size by about 250kB (800kB uncompressed) Common languages: bash, c, cpp, csharp, css, diff, go, graphql, ini, java, javascript, json, kotlin, less, lua, makefile, markdown, objectivec, perl, php-template, php, plaintext, python-repl, python, r, ruby, rust, scss, shell, sql, swift, typescript, vbnet, wasm, xml, yaml Additionally enabled languages: dockerfile, pgsql
Allows to individually enable languages.
Allows to enable additional languages that will not be autodetected.
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.
Works also, thx!
readonly pending: Set<string>; | ||
}; | ||
|
||
"before:highlight"(context: { language: string }) { |
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.
You can name class methods with string literals?
webpack.config.js
Outdated
const { bundledSyntaxHighlighters } = require("./src/shared/build-config"); | ||
const { lazySyntaxHighlighters } = require("./src/shared/build-config"); |
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.
If I'm not mistaken, this can be shortened to:
const { bundledSyntaxHighlighters } = require("./src/shared/build-config"); | |
const { lazySyntaxHighlighters } = require("./src/shared/build-config"); | |
const { bundledSyntaxHighlighters, lazySyntaxHighlighters } = require("./src/shared/build-config"); |
Description
Adds a plugin to highlight.js to detect when code should be highlighted using a language that is not yet loaded. A wrapped call to
md.render
provides a callback that will be called after a language had to be loaded, this allows components toforceUpdate
.Before
All available languages (listed here: https://highlightjs.org/download) are enabled and can be auto-detected.
After
Only the "common" set of 35 languages can be auto-detected, the remaining languages will be loaded individually on demand when explicitly specified by the author.
Uncommon languages, when auto-detected, are highlighted using the best fitting language of the common set.
client.js
size shrinks by about 240kB (compressed)