Skip to content

chore: migrate to shiki for syntax highlighting #4840

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

Merged
merged 4 commits into from
Apr 20, 2025
Merged

Conversation

techfg
Copy link
Collaborator

@techfg techfg commented Apr 20, 2025

What does this PR do?

react-syntax-highlighter has some vulnerabilities based on its use of an outdated prismjs and refractor (which uses prismjs). It no longer appears that react-syntax-highlighter is being maintained so its time for a new syntax highlighter.

There are several options out there but shiki appears to be the library that many are moving towards. Upon review, it provides several benefits for us with only main con:

  1. Pro: Feature parity with react-syntax-highlighter
  2. Pro: Integration with monaco-editor to allow us to have consistent theming for both code blocks and monaco editor
  3. Pro: Robust support for different themes, languages, etc.
  4. Pro: TextMate grammar powered, same engine as VS Code
  5. Con: Increases our bundle size for io package (raw: ~450k to ~1000k / gzip: ~148k to ~240k)

Given the gzip impact is small enough, this PR:

  1. migrates to shiki, removing react-syntax-highlighter
  2. fully supports js/ts/css/json/yaml/css syntax highlighting in markdown/code components (previously we only supported js/ts/yaml
  3. adds line number support in markdown & code component
  4. adds syntax highlighting to inline code blocks (previously we did not support this)
  5. uses same themes in monaco/markdown/code components
  6. improves legibility of monaco code view (was very difficult to discern yaml highlighting previously)
  7. eliminates the prismjs vulnerability

Testing

Manual testing confirms, ci & e2e will cover rest.

Before Markdown Component

image

After Markdown Component

image

Before Code Panel

image

After Code Panel

image

@techfg techfg requested a review from humandad April 20, 2025 10:51
@techfg techfg merged commit 405f207 into main Apr 20, 2025
6 checks passed
@techfg techfg deleted the chore/migrate-shiki branch April 20, 2025 22:48
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.

1 participant