Skip to content

Use Trix-compatible HTML for proper paragraph spacing#421

Open
nnemirovsky wants to merge 3 commits intobasecamp:mainfrom
nnemirovsky:fix/trix-compatible-html
Open

Use Trix-compatible HTML for proper paragraph spacing#421
nnemirovsky wants to merge 3 commits intobasecamp:mainfrom
nnemirovsky:fix/trix-compatible-html

Conversation

@nnemirovsky
Copy link
Copy Markdown
Contributor

@nnemirovsky nnemirovsky commented Apr 16, 2026

Summary

  • <div> instead of <p> — Trix uses <div> blocks, not <p>. Using <p> caused either double spacing (with <br> separator) or zero spacing (without) depending on browser CSS.
  • <div><br></div> for blank lines — matches Trix's native empty-line representation, producing consistent single-line paragraph gaps.
  • Preserve line breaks — consecutive lines now get <br> instead of being joined with a space, so single \n renders as a visible line break rather than being swallowed.

Before: MarkdownToHTML("Line 1\n\nLine 2")<p>Line 1</p>\n<br>\n<p>Line 2</p> (double-spaced in Basecamp)

After: MarkdownToHTML("Line 1\n\nLine 2")<div>Line 1</div>\n<div><br></div>\n<div>Line 2</div> (correct single spacing)

Verified by comparing generated HTML against a manually-edited Basecamp comment's HTML (fetched via API) — the output now matches Trix's native format exactly.

Test plan

  • All TestMarkdownToHTML* tests updated and passing
  • TestRoundTrip updated for new line-break preservation behavior
  • TestCheckinsAnswerCreate updated for <div> output
  • Tested end-to-end by posting a multi-section comment via CLI and confirming correct rendering in Basecamp

Summary by cubic

Switch MarkdownToHTML to output Trix-compatible HTML so Basecamp shows correct paragraph spacing. Also handle Trix-style <div> in HTMLToMarkdown so content round-trips cleanly.

  • Bug Fixes
    • Render paragraphs as <div>, blank lines as <div><br></div>, and preserve single \n as <br> inside paragraphs.
    • Map <div><br></div> to blank lines and <div> to paragraphs in HTMLToMarkdown; enable dotall matching for multiline <p>/<div> blocks; avoid extra newlines on round-trip; updated tests and check-ins expectation to the new format.

Written for commit 6aa2d47. Summary will update on new commits.

MarkdownToHTML previously wrapped paragraphs in <p> tags and inserted
bare <br> between blocks. Basecamp's Trix editor uses <div> blocks with
<div><br></div> for empty lines, so <p>-based output rendered with
incorrect spacing: either double-spaced (with <br>) or no spacing at
all (without).

Three changes:
- Paragraphs use <div> instead of <p> to match Trix's native format
- Blank lines produce <div><br></div> (Trix's empty line separator)
- Consecutive lines preserve line breaks via <br> instead of joining
  with spaces, so single newlines render as visible line breaks
Copilot AI review requested due to automatic review settings April 16, 2026 10:42
@github-actions github-actions bot added commands CLI command implementations tests Tests (unit and e2e) bug Something isn't working labels Apr 16, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the rich-text Markdown→HTML conversion to match Basecamp/Trix’s native HTML structure so paragraph spacing and single line breaks render consistently in Basecamp.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Changes:

  • Switch paragraph wrapper output from <p> to Trix-style <div>.
  • Represent blank lines as <div><br></div> instead of emitting a standalone <br>.
  • Preserve single newlines inside paragraphs by joining lines with <br> rather than spaces.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
internal/richtext/richtext.go Emits Trix-compatible <div> blocks and <div><br></div> separators; preserves single newlines via <br>.
internal/richtext/richtext_test.go Updates expected HTML outputs and adjusts round-trip behavior checks for the new line-break handling.
internal/commands/checkins_test.go Updates check-in answer creation test expectation to the new <div>-wrapped content.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/richtext/richtext.go
Comment thread internal/richtext/richtext.go Outdated
Comment thread internal/richtext/richtext_test.go Outdated
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="internal/richtext/richtext.go">

<violation number="1" location="internal/richtext/richtext.go:178">
P1: MarkdownToHTML now emits `<div>` paragraphs, but HTMLToMarkdown only normalizes `<p>` blocks, causing paragraph-spacing loss in round-trip conversions.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread internal/richtext/richtext.go
…und-trip

- Add <div><br></div> → blank line and <div> → paragraph handling in
  HTMLToMarkdown so Trix-native HTML round-trips correctly
- Drop trailing \n from <br> join in flushParagraph to prevent
  double-newlines on round-trip
- Strengthen round-trip test to verify line ordering and newline
  preservation between consecutive lines
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/richtext/richtext.go
Comment thread internal/richtext/richtext.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working commands CLI command implementations tests Tests (unit and e2e)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants