feat(markdown): syntax-highlight fenced code blocks#619
Conversation
There was a problem hiding this comment.
rainxchzed has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (19)
WalkthroughThis PR adds syntax-highlighted code blocks with light/dark theme support to README and release notes by integrating the ChangesSyntax Highlighting for Code Blocks
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (18)
core/presentation/src/commonMain/composeResources/files/whatsnew/18.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/ar/18.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/bn/18.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/es/18.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/fr/18.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/hi/18.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/it/18.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/ja/18.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/ko/18.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/pl/18.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/ru/18.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/tr/18.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/zh-CN/18.jsonfeature/details/presentation/build.gradle.ktsfeature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/components/sections/About.ktfeature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/components/sections/WhatsNew.ktfeature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/markdown/SyntaxHighlightedCode.ktgradle/libs.versions.toml
| 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), | ||
| ) |
There was a problem hiding this comment.
🧩 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.
| 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.
a12b5b1 to
7d9f753
Compare
There was a problem hiding this comment.
rainxchzed has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
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
Summary by CodeRabbit
New Features
Documentation