feat: codeblock highlight colors - #624
Open
eszlamczyk wants to merge 6 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds end-to-end style support for per-token fenced code block syntax colors (markdownStyle.codeBlock.syntaxColors), wiring the palette through style types, JS normalization, native component specs, and iOS/Android renderers/highlighters (with documentation + a Storybook QA surface).
Changes:
- Introduces
syntaxColorsoncodeBlockstyles (public + internal types) keyed by tree-sitter highlight token types. - Extends
normalizeMarkdownStyle(and.webdefaults) to provide a default GitHub-light palette and pass resolved token colors down to native. - Updates iOS/Android style/config + highlighter plumbing to consume the per-token palette; adds docs and an example Storybook story.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-enriched-markdown/src/types/MarkdownStyleInternal.ts | Adds internal CodeBlockSyntaxColorsInternal and threads it into internal code block style. |
| packages/react-native-enriched-markdown/src/types/MarkdownStyle.ts | Adds public codeBlock.syntaxColors API and documents token keys. |
| packages/react-native-enriched-markdown/src/normalizeMarkdownStyle.web.ts | Adds web default syntaxColors for type compatibility/future parity. |
| packages/react-native-enriched-markdown/src/normalizeMarkdownStyle.ts | Introduces default syntax palette and normalizes nested syntaxColors overrides. |
| packages/react-native-enriched-markdown/src/EnrichedMarkdownTextNativeComponent.ts | Exposes syntaxColors through the native component codegen TS types. |
| packages/react-native-enriched-markdown/src/EnrichedMarkdownNativeComponent.ts | Exposes syntaxColors through the native component codegen TS types. |
| packages/react-native-enriched-markdown/ios/views/ENRMCodeBlockContainerView.m | Passes StyleConfig into code-block highlighting call. |
| packages/react-native-enriched-markdown/ios/utils/StylePropsUtils.h | Applies per-token syntax colors from style props into StyleConfig by token ordinal. |
| packages/react-native-enriched-markdown/ios/utils/ENRMCodeBlockHighlighter.mm | Switches token coloring to read per-token colors from StyleConfig; adds range-based applier. |
| packages/react-native-enriched-markdown/ios/utils/ENRMCodeBlockHighlighter.h | Updates highlighting API to accept StyleConfig and adds ENRMApplyHighlightTokens. |
| packages/react-native-enriched-markdown/ios/styles/StyleConfig.mm | Stores per-token syntax colors in StyleConfig and exposes getter/setter by ordinal. |
| packages/react-native-enriched-markdown/ios/styles/StyleConfig.h | Declares StyleConfig API for per-token syntax colors. |
| packages/react-native-enriched-markdown/ios/renderer/CodeBlockRenderer.m | Applies foreground-only token spans for the commonmark code-block renderer. |
| packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/views/CodeBlockContainerView.kt | Passes CodeBlockStyle into the highlighter call. |
| packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/utils/common/CodeBlockHighlighter.kt | Uses style-provided per-token colors + supports offset-based application. |
| packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/styles/CodeBlockStyle.kt | Parses syntaxColors map into an ordinal-indexed color list. |
| packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/renderer/CodeBlockRenderer.kt | Applies foreground-only token spans over rendered code range. |
| docs/STYLES.md | Documents codeBlock.syntaxColors and each token key. |
| apps/react-native-example/.rnstorybook/stories/components/EnrichedMarkdownText/block/CodeHighlight.stories.tsx | Adds Storybook story to exercise per-token palettes across multiple languages. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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/Why?
First part of the code block syntax highlighting stack for #51.
This PR wires up the styling plumbing for per-token code block colors end to end, without shipping the highlighting engine itself. It adds a
syntaxColorsobject tocodeBlockstyles, keyed on tree-sitter highlight token types (keyword,string,comment,function,type, etc.), and threads it through:CodeBlockSyntaxColorsonCodeBlockStyle, plus the internal style type.normalizeMarkdownStyle(and the.webvariant) resolve the palette, applying the default GitHub-light colors and falling back to the code block's basecolorforoperatorColor/punctuation/variable/embedded.StyleConfig,ENRMCodeBlockHighlighter, andStylePropsUtilsconsume the colors.CodeBlockStyle,CodeBlockRenderer, andCodeBlockHighlighterconsume the colors.STYLES.mddocumentssyntaxColorsand each token key.CodeHighlightstory for the example app.Notes:
operatoris namedoperatorColorin the public API becauseoperatoris a reserved word in the generated native (C++) struct.This addresses #51 (does not close it) — it's the foundation for the highlighter that follows.
Testing
CodeHighlightStorybook story renders and accepts asyntaxColorspalette without regressions to existing code block rendering.color.Screenshots
Screenshots are included in second PR (#625) as without real paring its not viable to do anything with those colors
PR Checklist