Skip to content

feat(markdown): syntax-highlight fenced code blocks#619

Merged
rainxchzed merged 1 commit into
mainfrom
feat/markdown-syntax-highlighting
May 16, 2026
Merged

feat(markdown): syntax-highlight fenced code blocks#619
rainxchzed merged 1 commit into
mainfrom
feat/markdown-syntax-highlighting

Conversation

@rainxchzed
Copy link
Copy Markdown
Member

@rainxchzed rainxchzed commented May 16, 2026

Custom `codeFence` slot via `markdownComponents(...)` in About + WhatsNew. Uses `dev.snipme:highlights` 1.0.0 (KMP, ~250 KB jar). Supported languages: Kotlin, Java, Python, JS, TS, Rust, Swift, C#, Ruby, Perl, Shell, CoffeeScript, Dart. Unknown languages fall back to plain monospace.

Theme-aware: darcula on dark, atom on light. Highlights run inside `remember(code, language, isDark)` so they don't re-build on every recomposition. Horizontal scroll for long lines.

Test plan

  • Compile clean
  • Device: open Kotlin/Python/JS-heavy README. Verify keywords + types render in color. Theme toggle changes palette. Long lines horizontal-scroll without word wrap.

Summary by CodeRabbit

  • New Features

    • Code blocks in README and release notes now render with syntax highlighting for multiple languages and adapt colors for light/dark themes.
  • Documentation

    • "What's New" release notes updated across all supported locales to include the new syntax-highlighted code block note.

Review Change Stack

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

rainxchzed has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b8651968-e9d5-4929-b2c3-132438916e1b

📥 Commits

Reviewing files that changed from the base of the PR and between a12b5b1 and 7d9f753.

📒 Files selected for processing (19)
  • core/presentation/src/commonMain/composeResources/files/whatsnew/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/ar/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/bn/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/es/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/fr/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/hi/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/it/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/ja/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/ko/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/pl/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/ru/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/tr/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/zh-CN/18.json
  • feature/details/presentation/build.gradle.kts
  • feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/components/sections/About.kt
  • feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/components/sections/WhatsNew.kt
  • feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/markdown/GithubStoreMarkdownComponents.kt
  • feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/markdown/SyntaxHighlightedCode.kt
  • gradle/libs.versions.toml

Walkthrough

This PR adds syntax-highlighted code blocks with light/dark theme support to README and release notes by integrating the dev.snipme.highlights library, implementing a SyntaxHighlightedCode composable, wiring it into Markdown rendering in About and WhatsNew components, and documenting the feature across 12 localized release notes.

Changes

Syntax Highlighting for Code Blocks

Layer / File(s) Summary
Gradle dependency setup
gradle/libs.versions.toml, feature/details/presentation/build.gradle.kts
The dev.snipme:highlights library version 1.0.0 is added to the version catalog and wired into the feature details presentation module's commonMain dependencies.
SyntaxHighlightedCode composable and helpers
feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/markdown/SyntaxHighlightedCode.kt
A new composable extracts language hints from Markdown fence AST nodes via extractFenceContent, maps language strings to SyntaxLanguage via languageOf, generates themed highlight tokens via buildHighlighted using the highlights library, converts token ranges into styled AnnotatedString spans with fallback on failure, and renders horizontally scrollable monospace text in a rounded container.
Integrate syntax highlighter into Markdown rendering
feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/components/sections/About.kt, feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/components/sections/WhatsNew.kt, feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/markdown/GithubStoreMarkdownComponents.kt
Both components now detect dark theme mode and override the Markdown components configuration to use SyntaxHighlightedCode for code-fence blocks, passing the isDark boolean for theme-aware styling.
Release notes documentation
core/presentation/src/commonMain/composeResources/files/whatsnew/{18.json,ar/18.json,bn/18.json,es/18.json,fr/18.json,hi/18.json,it/18.json,ja/18.json,ko/18.json,pl/18.json,ru/18.json,tr/18.json,zh-CN/18.json}
A new bullet is added to the IMPROVED section of version 18 release notes in all 13 localized variants describing syntax-highlighted code blocks in README and release notes with support for multiple languages and light/dark theme-aware colors.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • OpenHub-Store/GitHub-Store#271: Previously augmented the same ExpandableMarkdownContent and About/WhatsNew components for expand/collapse functionality, which is now extended with syntax-highlighted code blocks.
  • OpenHub-Store/GitHub-Store#616: Modifies the Markdown rendering pipeline and related components; this PR adds fenced code syntax highlighting while that PR added Markdown alert block rendering.

Poem

🐰 With highlights so bright,
Code blocks now take flight—
Colors dance left and right,
Dark themes and light!
README shines through the night. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding syntax highlighting to fenced code blocks in markdown rendering.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/markdown-syntax-highlighting

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/markdown/SyntaxHighlightedCode.kt`:
- Around line 74-81: The CODE_FENCE_CONTENT branch is inserting a newline before
appending content and the EOL branch also appends newlines, causing double
breaks; in the handler for MarkdownTokenTypes.CODE_FENCE_CONTENT (the block that
uses sawContent, body.append, and content.substring(child.startOffset,
child.endOffset)), remove the pre-content body.append('\n') so lines rely on the
MarkdownTokenTypes.EOL branch to add line terminators, keeping sawContent logic
intact; ensure the MarkdownTokenTypes.EOL branch still conditionally appends
'\n' only when sawContent is true.
- Around line 43-54: The Text composable rendering the highlighted code
currently allows soft wrapping which breaks horizontal scrolling; update the
Text call that displays "highlighted" to disable soft wrapping (set softWrap =
false) so long lines remain on a single line and horizontalScroll works as
intended, and optionally set an appropriate overflow behavior (e.g.,
TextOverflow.Clip or Visible) to ensure clipped/visible content behaves
correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3607d406-f88a-4f71-bf5d-408fccd95159

📥 Commits

Reviewing files that changed from the base of the PR and between 01226dc and a12b5b1.

📒 Files selected for processing (18)
  • core/presentation/src/commonMain/composeResources/files/whatsnew/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/ar/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/bn/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/es/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/fr/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/hi/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/it/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/ja/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/ko/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/pl/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/ru/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/tr/18.json
  • core/presentation/src/commonMain/composeResources/files/whatsnew/zh-CN/18.json
  • feature/details/presentation/build.gradle.kts
  • feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/components/sections/About.kt
  • feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/components/sections/WhatsNew.kt
  • feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/markdown/SyntaxHighlightedCode.kt
  • gradle/libs.versions.toml

Comment on lines +43 to +54
Text(
text = highlighted,
style = MaterialTheme.typography.bodySmall.copy(fontFamily = FontFamily.Monospace),
color = onContainer,
modifier =
Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(8.dp))
.background(container)
.horizontalScroll(rememberScrollState())
.padding(horizontal = 12.dp, vertical = 10.dp),
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

fd -type f -name "SyntaxHighlightedCode.kt"

Repository: OpenHub-Store/GitHub-Store

Length of output: 241


🏁 Script executed:

cat -n "feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/markdown/SyntaxHighlightedCode.kt"

Repository: OpenHub-Store/GitHub-Store

Length of output: 6719


Disable soft wrapping to preserve horizontal scrolling for long code lines.

The Text composable defaults to softWrap = true, which causes long code lines to wrap to multiple lines instead of scrolling horizontally. This defeats the purpose of the .horizontalScroll() modifier.

Suggested fix
 import androidx.compose.ui.text.font.FontFamily
+import androidx.compose.ui.text.style.TextOverflow
 import androidx.compose.ui.unit.dp
@@
     Text(
         text = highlighted,
         style = MaterialTheme.typography.bodySmall.copy(fontFamily = FontFamily.Monospace),
         color = onContainer,
+        softWrap = false,
+        overflow = TextOverflow.Clip,
         modifier =
             Modifier
                 .fillMaxWidth()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Text(
text = highlighted,
style = MaterialTheme.typography.bodySmall.copy(fontFamily = FontFamily.Monospace),
color = onContainer,
modifier =
Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(8.dp))
.background(container)
.horizontalScroll(rememberScrollState())
.padding(horizontal = 12.dp, vertical = 10.dp),
)
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
Text(
text = highlighted,
style = MaterialTheme.typography.bodySmall.copy(fontFamily = FontFamily.Monospace),
color = onContainer,
softWrap = false,
overflow = TextOverflow.Clip,
modifier =
Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(8.dp))
.background(container)
.horizontalScroll(rememberScrollState())
.padding(horizontal = 12.dp, vertical = 10.dp),
)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/markdown/SyntaxHighlightedCode.kt`
around lines 43 - 54, The Text composable rendering the highlighted code
currently allows soft wrapping which breaks horizontal scrolling; update the
Text call that displays "highlighted" to disable soft wrapping (set softWrap =
false) so long lines remain on a single line and horizontalScroll works as
intended, and optionally set an appropriate overflow behavior (e.g.,
TextOverflow.Clip or Visible) to ensure clipped/visible content behaves
correctly.

@rainxchzed rainxchzed force-pushed the feat/markdown-syntax-highlighting branch from a12b5b1 to 7d9f753 Compare May 16, 2026 15:43
@rainxchzed rainxchzed merged commit 1d5a5d3 into main May 16, 2026
1 check was pending
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

rainxchzed has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

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