Add syntax highlighting to snippet card previews - #15
Merged
Conversation
Snippet card previews (home, folder view, trash) rendered their truncated body as flat dimmed text. They now render statically highlighted tokens using lowlight (shared with the Markdown editor's code blocks), keeping the subdued, faded look. - New snippetPreview.tsx owns the truncation, a LanguageId → highlight.js grammar map, lazy lowlight loading (dynamic import so grammars stay out of the home page's initial bundle), and a hast → React converter that re-opens tokens across line breaks. Results are memoized per language + truncated text so hover/selection/drag never re-parse; unsupported languages and parse failures fall back to plain text. - SnippetCard consumes the highlighted lines, keeping line numbers and the gradient fade; tokens are slightly muted to match the preview's look. - globals.css hljs token colors are shared with the previews via :is() so both stay visually coherent in light and dark themes. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01FrdhgUkHWaZGrXXiSL2DQx
Contributor
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
klipcode | f3c5b9f | Commit Preview URL Branch Preview URL |
Jul 10 2026, 09:57 PM |
martinezharo
force-pushed
the
claude/snippet-cards-syntax-highlight-1iifrm
branch
from
July 10, 2026 21:55
4f9f062 to
f3c5b9f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Snippet card previews (home, folder view, and trash) rendered their truncated body as flat, dimmed plain text. They now show statically syntax-highlighted code, reusing the same lowlight grammars and VS Code token colors as the Markdown editor's code blocks so everything stays visually coherent.
Before → after (dark theme, JS card): keywords, strings (including template-literal
${}substitution), comments, numbers and function names are now colored, while the preview keeps its subdued, faded look and gradient fade.How
src/components/SnippetCards/snippetPreview.tsx(new)buildPreviewLines, moved fromSnippetCard).LanguageIdvalues to highlight.js grammar names (html→xml,toml→ini,tsx/jsxreuse their base grammar, etc.).import()so the grammars stay out of the home page's initial bundle — the chunk is shared with the Markdown editor, which already usescreateLowlight(common).src/components/SnippetCards/SnippetCard.tsx— consumes the highlighted lines, keeping line numbers and the fade; tokens are slightly muted (opacity-[0.85]) to respect the current preview aesthetic.src/app/globals.css— the existing.hljs-*token color rules are shared with the previews via:is(.klipcode-md, .klipcode-code-preview), for both light and dark themes.Testing
pnpm lintandpnpm test(139 tests) pass via the pre-commit hook.tsc --noEmitclean.🤖 Generated with Claude Code
https://claude.ai/code/session_01FrdhgUkHWaZGrXXiSL2DQx
Generated by Claude Code