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

Add syntax highlighting with Shikiji #17

Merged
merged 4 commits into from
Jan 14, 2024
Merged

Conversation

isker
Copy link
Owner

@isker isker commented Jan 14, 2024

At long last, we have syntax highlighting with acceptable tradeoffs.

Shikiji is intended to be the next version of the longstanding Shiki.
It's fundamentally better in that it simply uses ESM and dynamic imports
to break out the wasm blob and the many language grammars into their own
JS assets, instead of an ad-hoc asset fetching meechanism. This means it
does the right thing when integrating with SvelteKit's vite build
tooling, for free.

I have had to make minor patches to Shikiji to get it to have the exact
APIs that I want. I could have used the stock ones but they would result
in a jankier (and slightly less performant) integration. I will propose
upstreaming these changes, but I doubt they will all be acceptable.

The patches required a switch to yarn. I was long getting tired of
npm's general jank, but it simply lacks this feature entirely.

The exact approach to highlighting is discussed in the new LineGroup
component. The data returned by content-parser in the API also had to
change to more easily merge with Shikiji's highlights.

Closes #3.

isker added 4 commits January 14, 2024 16:28
I'd like to patch shikiji and npm does not offer an easy way to do that.
I have also had some terrible times doing svelte(kit) updates with peer
dependencies in npm, having to manually muck around in package-lock.json
to break strange deadlocks. Let's give up and use yarn.
At long last, we have syntax highlighting with acceptable tradeoffs.

Shikiji is intended to be the next version of the longstanding Shiki.
It's fundamentally better in that it simply uses ESM and dynamic imports
to break out the wasm blob and the many language grammars into their own
JS assets, instead of an ad-hoc asset fetching meechanism. This means it
does the right thing when integrating with SvelteKit's vite build
tooling, for free.

I have had to make minor patches to Shikiji to get it to have the exact
APIs that I want. I could have used the stock ones but they would result
in a jankier (and slightly less performant) integration. I will propose
upstreaming these changes, but I doubt they will all be acceptable.

The exact approach to highlighting is discussed in the new LineGroup
component. The data returned by content-parser in the API also had to
change to more easily merge with Shikiji's highlights.
@isker isker merged commit 9a0407e into master Jan 14, 2024
3 checks passed
@isker isker deleted the syntax-highlighting-shikiji branch January 14, 2024 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Syntax highlighting
1 participant