fix(api,text): Fix language normalization and style preservation in code blocks Improve code block rendering and text styling:#97
Conversation
…ode blocks
Improve code block rendering and text styling:
1. Add language normalization to mimeTypeToLanguage() to handle plain language identifiers (typescript, go, sql) in addition to MIME types, fixing regression where CodeBlock("typescript", ...) produced unwrapped escaped text.
2. Implement AppendStyle() method on Text to merge Tailwind classes without duplication, enabling callers to preserve existing styles (width/truncation directives) when applying new ones.
3. Fix Text.Wrap() to avoid doubling receiver content by creating new Text root instead of calling Add(t) on receiver.
4. Update Status.Apply() to use AppendStyle() instead of replacing style, preserving caller-set classes like truncation directives.
5. Refactor chroma CSS to use block-level <pre> elements with proper wrapping instead of inline display, improving code block rendering in tree views.
6. Add nil checks in TryTypedValue() to handle nil pointers and interfaces gracefully.
Includes comprehensive test coverage for language normalization, HTML wrapping, style deduplication, and truncation behavior.
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 43 minutes and 59 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe changes enhance text styling composition and code highlighting behavior. A new method enables appending Tailwind classes without overwriting existing styles, CSS rules for syntax highlighting are updated for improved wrapping, and style preservation is integrated into status display rendering with supporting tests. Changes
Possibly related PRs
🚥 Pre-merge checks | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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 the current code and only fix it if needed.
Inline comments:
In `@api/text.go`:
- Around line 662-665: The mimeTypeToLanguage function does case-sensitive MIME
matching causing mixed-case inputs to fail; convert the incoming mime string to
a normalized form (e.g., strings.ToLower(strings.TrimSpace(mime))) at the start
of mimeTypeToLanguage, then use that normalized value for the contains check and
all subsequent comparisons, including the matching block around lines 667-678,
and keep calling normalizeLanguage for short names as before; update references
to use the normalized variable rather than the original mime parameter.
- Around line 289-293: The Wrap implementation is dropping additional style args
by using only style[0] for the prefix/suffix Texts; update the three Add(...)
calls in the expression that constructs and returns Text{} so they apply the
entire style slice instead of a single element (use the full style slice for the
Style field when creating Text for prefix and suffix, i.e., replace Style:
style[0] with the full style value), ensuring prefix, t, and suffix all receive
the same set of styles via the Text.Add and Text{Content:..., Style:...} usages.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4cbb40af-f258-4c2e-8f8b-c7c33edf7f5c
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (7)
api/code.goapi/code_test.goapi/meta.goapi/text.goapi/text_test.gotask/render_test.gotask/task.go
| if len(style) > 0 { | ||
| return t.Add(Text{Content: prefix, Style: style[0]}). | ||
| return Text{}. | ||
| Add(Text{Content: prefix, Style: style[0]}). | ||
| Add(t). | ||
| Add(Text{Content: suffix, Style: style[0]}) |
There was a problem hiding this comment.
Wrap drops additional style arguments.
Line 291/Line 293 apply only style[0], so callers passing multiple style args lose classes.
🔧 Proposed fix
func (t Text) Wrap(prefix, suffix string, style ...string) Text {
if len(style) > 0 {
+ wrapStyle := strings.Join(style, " ")
return Text{}.
- Add(Text{Content: prefix, Style: style[0]}).
+ Add(Text{Content: prefix, Style: wrapStyle}).
Add(t).
- Add(Text{Content: suffix, Style: style[0]})
+ Add(Text{Content: suffix, Style: wrapStyle})
}📝 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.
| if len(style) > 0 { | |
| return t.Add(Text{Content: prefix, Style: style[0]}). | |
| return Text{}. | |
| Add(Text{Content: prefix, Style: style[0]}). | |
| Add(t). | |
| Add(Text{Content: suffix, Style: style[0]}) | |
| func (t Text) Wrap(prefix, suffix string, style ...string) Text { | |
| if len(style) > 0 { | |
| wrapStyle := strings.Join(style, " ") | |
| return Text{}. | |
| Add(Text{Content: prefix, Style: wrapStyle}). | |
| Add(t). | |
| Add(Text{Content: suffix, Style: wrapStyle}) | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@api/text.go` around lines 289 - 293, The Wrap implementation is dropping
additional style args by using only style[0] for the prefix/suffix Texts; update
the three Add(...) calls in the expression that constructs and returns Text{} so
they apply the entire style slice instead of a single element (use the full
style slice for the Style field when creating Text for prefix and suffix, i.e.,
replace Style: style[0] with the full style value), ensuring prefix, t, and
suffix all receive the same set of styles via the Text.Add and Text{Content:...,
Style:...} usages.
Co-authored-by: Moshe Immerman <moshe@flanksource.com>
## [1.21.4](v1.21.3...v1.21.4) (2026-04-14) ### 🐛 Bug Fixes * **api,text:** Fix language normalization and style preservation in code blocks Improve code block rendering and text styling: ([#97](#97)) ([4204ea9](4204ea9))
|
🎉 This PR is included in version 1.21.4 |
Summary by CodeRabbit
New Features
Bug Fixes