Skip to content

fix(api,text): Fix language normalization and style preservation in code blocks Improve code block rendering and text styling:#97

Merged
moshloop merged 2 commits intomainfrom
pr/styles
Apr 14, 2026
Merged

fix(api,text): Fix language normalization and style preservation in code blocks Improve code block rendering and text styling:#97
moshloop merged 2 commits intomainfrom
pr/styles

Conversation

@moshloop
Copy link
Copy Markdown
Member

@moshloop moshloop commented Apr 14, 2026

Summary by CodeRabbit

  • New Features

    • Added text style composition with automatic class deduplication.
  • Bug Fixes

    • Enhanced code block CSS styling with improved line wrapping, spacing, and rounded corners.
    • Fixed text wrapping content duplication.
    • Improved code language detection across multiple syntax types.
    • Preserved style information in status displays.
    • Added nil-safety validation.

…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.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 14, 2026

Warning

Rate limit exceeded

@moshloop has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 43 minutes and 59 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9e1497ca-7aa2-4a2b-8616-5746cf4eeb72

📥 Commits

Reviewing files that changed from the base of the PR and between a95bc43 and 1beb8dd.

📒 Files selected for processing (1)
  • api/text.go

Walkthrough

The 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

Cohort / File(s) Summary
Code Highlighting
api/code.go, api/code_test.go
Modified Chroma CSS generation to target pre.chroma with block-level wrapping styles (white-space: pre-wrap, word-break: break-word, overflow-wrap: anywhere) and spacing adjustments. Added tests validating language normalization and HTML wrapper generation with token highlighting.
Text Styling
api/text.go, api/text_test.go
Introduced AppendStyle() method to merge Tailwind classes via uniqueStyles. Modified Wrap() to construct new styled nodes instead of duplicating receiver. Updated mimeTypeToLanguage() to normalize plain language identifiers and added TypeScript mapping. Comprehensive test coverage for style deduplication and token preservation.
Task Status Rendering
task/task.go, task/render_test.go
Changed Status.Apply() to append status styles via AppendStyle() instead of overwriting, preserving incoming style directives. Added tests for prompt truncation behavior and repeated style application without duplication, with Tailwind terminal-width mocking for deterministic testing.
Meta Utilities
api/meta.go
Added nil-safety checks to TryTypedValue() to return nil immediately for nil input values, pointers, or interface values before type-switching logic.

Possibly related PRs

  • Misc fixes #64: Introduces the uniqueStyles refactor that underpins the new AppendStyle() method for deduplicating Tailwind class tokens.
🚥 Pre-merge checks | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided; the repository requires a structured description with sections like Type of Change, Testing, and Checklist. Add a detailed description following the repository template, including the type of change, testing status, and completed checklist items.
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive Title is partially related to the changeset; it mentions language normalization and style preservation in code blocks, which are real aspects of the changes, but the phrasing is incomplete and cuts off mid-sentence. Complete the title by finishing the sentence and making it more concise. Example: 'Fix language normalization and style preservation in code blocks.'

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pr/styles
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch pr/styles

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 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

📥 Commits

Reviewing files that changed from the base of the PR and between 42a243c and a95bc43.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • api/code.go
  • api/code_test.go
  • api/meta.go
  • api/text.go
  • api/text_test.go
  • task/render_test.go
  • task/task.go

Comment thread api/text.go
Comment on lines 289 to 293
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]})
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 | 🟡 Minor

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.

Suggested change
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.

Comment thread api/text.go
Comment thread api/text.go
Co-authored-by: Moshe Immerman <moshe@flanksource.com>
@moshloop moshloop enabled auto-merge (squash) April 14, 2026 15:38
@moshloop moshloop merged commit 4204ea9 into main Apr 14, 2026
12 of 14 checks passed
@moshloop moshloop deleted the pr/styles branch April 14, 2026 15:41
flankbot pushed a commit that referenced this pull request Apr 14, 2026
## [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))
@flankbot
Copy link
Copy Markdown

🎉 This PR is included in version 1.21.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants