-
-
Notifications
You must be signed in to change notification settings - Fork 382
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
RFC: Browser support & API changes #91
Comments
I think all these changes are good ideas 👍🏻 |
About the loading in the browser, since we shipped the grammars and themes in different packages from Ships within the same packageSo the in the browser, we can load them with the relative path like New option for specifying the CDN providersSomething like await shiki.getHighlighter({
theme: 'nord',
themes: ['nord', 'github-light'],
languages: ['js', 'ts', 'html', 'vue'],
cdnProvider: 'unpkg', // jsdelivr, cdnjs, github, npm?
}) This could work in a more general way as they are loaded from absolute paths like Which one should we take? |
I think "Ships within the same package" is good enough. Maybe we could have a package called |
This would be very nice and is the first thing I looked for when discovering this repo. You already wrote your sources as ES modules so it was surprising to see the distribution isn't also ESM.
I would recommend not doing this. It would be a bad idea i think to make any assumptions over where the related data files live. Instead, I would require browser consumers to either explicitly pass the path or the already loaded object: await highlighter.loadTheme('./my-custom/path/nord-theme.json'); As you have no idea what the production directory structure will be, and it is very likely it won't be what it was in this repo. For example, in most of my repo's we create lazily loaded bundles which will not live at the same place they did originally on disk. So would need to specify the path to retrieve these themes and language files from explicitly. |
Currently,
shiki
can only work on Node.js. There is the common usage for using a syntax highlighter right in the browser for dynamic contents or building a playground. This RFC is trying to make some changes to the current implementation to make shiki able to run on both Node and browsers isomorphically. #22I have made a hack build to replace
fs.readFileSync
with a syncXMLHttpRequest
to fetch the data over http. You can try it at https://antfu.github.io/shiki-browser/. The main problem is that shiki will load all the grammars and themes ingetHighligter
which will cause high & redundant traffic & load cost in the browser.Internal Changes
Wrap the current
fs.readFileSync
with an isomorphic loader likeAPI Changes
New field
themes
andlanguages
forgetHighlighter
to explicitly define what should be loaded. If not provided, they will work the same as we currently have.For users using bundlers like Webpack to build their app, they could make the loading by the bundler instead of CDN.
Also, add the ability to load grammars/themes incrementally for the highlighter
A third argument (optional) for
codeToHtml
to explicitly change the theme. Should raise an error if the provided theme is not loaded. This would be also useful for #33Build
Providing
umd
andesm
builds.Implementation
PR #109 implemented this proposal.
/cc @octref @orta
The text was updated successfully, but these errors were encountered: