Skip to content

fix: shiki -> react-syntax-highlighter #136

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 2 commits into from
May 3, 2024

Conversation

epoll31
Copy link
Contributor

@epoll31 epoll31 commented May 3, 2024

Description

using react-syntax-highlighter in Code now / ComponentPreview references Code again / customizable prism theme

Related Issue

Fixes #135

Proposed Changes

  • Using react-syntax-highlighter instead of codeToHtml in src/components/code/Code.tsx
  • Using Code instead of react-syntax-highlighter in src/components/code/ComponentPreview.tsx to only reference react-syntax-highlighter in one place
  • react-syntax-highlighter uses a theme defined in src/components/code/theme.ts

Screenshots

Screenshot 2024-05-03 at 10 57 04 AM

Checklist

Please check the boxes that apply:

  • I have tested the changes locally
  • I ran npm run build and build is successful
  • I have added necessary documentation (if applicable)
  • I have updated the credits.md file (if applicable)

@epoll31 epoll31 requested a review from Ansub as a code owner May 3, 2024 17:58
Copy link

vercel bot commented May 3, 2024

@epoll31 is attempting to deploy a commit to the SyntaxUI Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented May 3, 2024

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

Name Status Preview Comments Updated (UTC)
syntax-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 3, 2024 6:13pm

@Ansub
Copy link
Member

Ansub commented May 3, 2024

what are these useMemo() doing?

image

@epoll31
Copy link
Contributor Author

epoll31 commented May 3, 2024

what are these useMemo() doing?

image

I used them to avoid performing those string mutations on rerenders. They are pretty simple so I don't think that they are vital, but I thought it would be better with them.

Specifically, the code one trims the extra white space and newlines. And, the language one removes "language-" from the language or returns "plaintext" when no language specified

Comment on lines +38 to +42
const lang = useMemo(
() => (rawLang ? rawLang.replace('language-', '') : 'plaintext'),
[rawLang],
)
const code = useMemo(() => rawCode.trim(), [rawCode])
Copy link
Member

Choose a reason for hiding this comment

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

what are these useMemo() doing?

@Ansub Ansub merged commit bc8c003 into SyntaxUI:main May 3, 2024
2 checks passed
@Ansub Ansub added the enhancement New feature or request label May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: Shiki Loading Times
2 participants