Skip to content

Initial attempt at a code splitted syntax highligher #20

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
Jul 10, 2022

Conversation

soupaJ
Copy link
Collaborator

@soupaJ soupaJ commented Jun 26, 2022

Description

This is my initial attempt at adding syntax highlighting. I had a few goals in mind while developing:

  1. Bundle size should not increase for documents that don't contain code blocks.
  2. For code blocks, only download the required language packs.
  3. Try to support many languages. While looking for a syntax highlighter, I found several for JS and TS, but not many for multiple languages. I landed on Codemirror v6 which seemed to work pretty good out of the box with a few tweaks as well as working on mobile.
  4. Find a theme that matches Gistdoc styling. After a little bit of discussion, we landed on a theme that closely matches the Nord theme.

In order to use Suspense for lazy loading the syntax highlighter with a fallback, I needed to update to React v18 which also required updating Next.js to the latest.

NOTE: This does not include the line highlighting feature through the markdown metadata yet. I'll add that in a separate PR.

Screenshots

Here's an example of the theme

@vercel
Copy link

vercel bot commented Jun 26, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
gistdoc ✅ Ready (Inspect) Visit Preview Jul 1, 2022 at 3:13AM (UTC)

attempts to match the nord theme colors
@soupaJ soupaJ changed the title WIP: Initial attempt at a code splitted syntax highligher Initial attempt at a code splitted syntax highligher Jun 27, 2022
@soupaJ soupaJ marked this pull request as ready for review June 27, 2022 04:38
@soupaJ soupaJ requested a review from jkulton June 27, 2022 04:38
@jkulton jkulton self-assigned this Jun 27, 2022
Copy link
Owner

@jkulton jkulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks @soupaJ! Just left a few comments, nothing to change really.

@jkulton jkulton merged commit 2278b90 into jkulton:main Jul 10, 2022
@soupaJ soupaJ deleted the feature/syntax-highlighter branch July 10, 2022 17:48
@jkulton
Copy link
Owner

jkulton commented Jul 10, 2022

Added to the changelog here! 🎉

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.

2 participants