Skip to content

Convert HTML content to markdown in presenter output#184

Merged
jeremy merged 3 commits intomainfrom
card-assignable-md
Mar 3, 2026
Merged

Convert HTML content to markdown in presenter output#184
jeremy merged 3 commits intomainfrom
card-assignable-md

Conversation

@jeremy
Copy link
Member

@jeremy jeremy commented Mar 3, 2026

Summary

  • Detect <bc-attachment> tags in richtext.IsHTML() so pure-attachment payloads (mentions, file refs) no longer bypass HTML detection
  • Convert HTML → markdown in formatText(), the universal text formatting path, so all output modes (terminal, markdown, JSON) get clean content
  • Collapse multi-line converted content to single lines in compact renderers: list rows, task items, GFM table cells, and task metadata
  • Normalize headlines containing HTML: convert, collapse to single line, strip emphasis markers that would nest with the bold/primary rendering context

Test plan

  • make check passes (vet, lint, unit tests, e2e tests)
  • 13 new test cases covering HTML conversion, plain passthrough, bc-attachment handling, singleLine() behavior, headline normalization with <strong>, task metadata HTML, list rows, and table cells
  • Manual: basecamp reports assigned — no HTML tags in terminal output
  • Manual: basecamp reports assigned -m — readable markdown, no raw HTML

jeremy added 2 commits March 3, 2026 12:00
Pure bc-attachment payloads (Basecamp mentions, file references) without
wrapping <div>/<p> tags bypassed HTML detection because reSafeTag did not
include bc-attachment. This caused raw tags to leak through formatText()
and every downstream renderer.
The Basecamp API returns Trix HTML in content, description, and body
fields. The TUI already converts via richtext.HTMLToMarkdown → glamour,
but the CLI presenter rendered strings verbatim, leaking <div>, <br>,
<bc-attachment>, <blockquote>, etc. into every output mode.

- formatText() now detects HTML and converts to markdown at the
  universal formatting point, so all output modes benefit
- singleLine() helper collapses multi-line converted content for
  compact renderers (list rows, task items, table cells, metadata)
- RenderHeadline() normalizes HTML headlines and strips emphasis
  markers that would nest with the bold/primary rendering context
Copilot AI review requested due to automatic review settings March 3, 2026 20:00
@github-actions github-actions bot added tests Tests (unit and e2e) output Output formatting and presentation labels Mar 3, 2026
@github-actions github-actions bot added the bug Something isn't working label Mar 3, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 06a5ae7b9a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link

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 presenter output pipeline to detect Basecamp rich-text HTML (including pure <bc-attachment> payloads) and convert HTML to Markdown consistently, while keeping list/table/task renderers compact by collapsing multi-line conversions.

Changes:

  • Extend richtext.IsHTML() detection to treat <bc-attachment> as HTML.
  • Convert HTML → Markdown in presenter.formatText() (used by FormatField) and normalize headlines that contain HTML.
  • Collapse formatted values to a single line in compact renderers (list rows, task items, markdown table cells), with added tests.

Reviewed changes

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

Show a summary per file
File Description
internal/richtext/richtext.go Expands HTML detection regex to include bc-attachment.
internal/richtext/richtext_test.go Adds IsHTML coverage for bc-attachment variants.
internal/presenter/format.go Adds HTML→Markdown conversion to formatText(); introduces singleLine().
internal/presenter/template.go Normalizes HTML headlines (convert→single-line→strip bold markers).
internal/presenter/render.go Collapses list/table/task rendered values to a single line for compact views.
internal/presenter/presenter_test.go Adds tests for HTML conversion, single-line collapsing, and headline/task/table behavior.

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

- singleLine: add fast-path when no newlines to avoid slice allocation
  on the common case (every cell/value in list rendering)
- RenderHeadline: replace blanket strings.ReplaceAll("**","") with regex
  that unwraps **...** pairs, preserving literal ** in content like 2**10
- Narrow doc comment to describe bold-only unwrapping, not general emphasis
@jeremy jeremy merged commit 88114fa into main Mar 3, 2026
21 checks passed
@jeremy jeremy deleted the card-assignable-md branch March 3, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working output Output formatting and presentation tests Tests (unit and e2e)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants