Skip to content

Convert Markdown mention links inside HTML blocks to mention chips#532

Merged
robzolkos merged 5 commits into
mainfrom
fix-mention-link-in-html-block
Jul 13, 2026
Merged

Convert Markdown mention links inside HTML blocks to mention chips#532
robzolkos merged 5 commits into
mainfrom
fix-mention-link-in-html-block

Conversation

@robzolkos

@robzolkos robzolkos commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

A [@Name](mention:SGID) or [@Name](person:ID) mention authored inside an author-supplied HTML block rendered as a correct chip for the first name token followed by literal garbage — e.g. a valid @Jorge chip immediately trailed by the literal text Manrubia](mention:SGID).

Root cause

When input is detected as HTML, MarkdownToHTML passes it through verbatim and never runs goldmark, so the Markdown mention link is never converted to an <a href="mention:..."> anchor. resolveMentionAnchors matched nothing, and the fuzzy @Name pass then matched only the first name token (its regex stops at the first space) — turning that into a chip and leaving the rest of the link as literal text.

Fix

Add a resolveMentionMarkdownLinks pass to ResolveMentions that recognizes the literal [@Name](mention:SGID) / [@Name](person:ID) form and converts it to a <bc-attachment> mention before the fuzzy pass runs. It reuses the existing skip guards, so links inside <code>, existing attachments, or tags (i.e. documentation) are left untouched.

Because the fix lives in the richtext layer, it covers every call site that composes rich text: comments, messages, cards, chat, check-ins, documents, todos, and schedule.

Validation

  • New regression tests: TestResolveMentions_MarkdownLinkInHTMLBlock (mention scheme, person scheme, and the <code> documentation guard) and TestMentionInHTMLBlock_FullPipeline (full MarkdownToHTML → ResolveMentions sequence asserting exactly one chip and no residue).
  • Existing fuzzy/anchor/sgid mention tests unchanged and green.
  • Verified end-to-end against live Basecamp: before the fix, a mention link in an HTML block stored a chip plus trailing literal ](mention:…) text; after the fix, the same input stores a single clean mention chip with no residue.
  • bin/ci passes.

Reported in card 10088583638.


Summary by cubic

Fixes Markdown mention links inside author-supplied HTML blocks so they render as a single clean mention chip across rich-text surfaces. Adds a faster exclusion index to skip tags/code/attachments and prevent partial chips.

  • Bug Fixes

    • Convert literal [@Name](mention:SGID) / [@Name](person:ID) in HTML blocks to <bc-attachment> before the fuzzy pass; person: uses lookupByID.
    • Hardened matching: no cross-tag matches; skip inside <code>, <pre>, existing <bc-attachment>, or quoted attributes; unescape entities; error on person: when no lookup is provided.
  • Refactors

    • Share deterministic mention resolution for anchors and Markdown links; precompute mention exclusion spans (HTML tags and protected elements) and binary-search for containment.
    • Expanded tests cover both schemes, guards, multiple links, resolution after closed blocks/attachments, error paths, and the full MarkdownToHTML → ResolveMentions pipeline.

Written for commit 1e8c291. Summary will update on new commits.

Review in cubic

Copilot AI review requested due to automatic review settings July 13, 2026 13:43
@github-actions github-actions Bot added the tests Tests (unit and e2e) label Jul 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a rich-text edge case where Markdown-style mention links written inside author-supplied HTML blocks bypass the Markdown parser and were partially converted by the fuzzy mention pass, leaving trailing literal garbage text. The change adds a dedicated resolution pass in the richtext layer so mention links are converted into a single <bc-attachment> chip before fuzzy matching runs, affecting all rich-text surfaces consistently.

Changes:

  • Added a new resolveMentionMarkdownLinks pass to convert literal [@Name](mention:SGID) / [@Name](person:ID) into mention chips when Markdown-to-HTML conversion is skipped for HTML blocks.
  • Updated ResolveMentions to run this new pass before @sgid: and fuzzy @Name resolution.
  • Added regression tests covering both schemes, skip-guards (e.g., <code>), and the full MarkdownToHTML → ResolveMentions pipeline.

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.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/richtext/richtext.go Adds regex + a new mention-resolution pass for literal Markdown mention links inside HTML blocks, and integrates it into the ResolveMentions pipeline.
internal/richtext/richtext_test.go Adds regression tests validating correct chip conversion and no residual literal markdown link text in the full pipeline.

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

Comment thread internal/richtext/richtext.go

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

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.

No issues found across 2 files

Re-trigger cubic

A `[@name](mention:SGID)` or `[@name](person:ID)` mention authored inside an
author-supplied HTML block rendered as a correct chip for the first name token
followed by literal garbage — e.g. a valid `@Jorge` chip trailed by the literal
text `Manrubia](mention:SGID)`.

Root cause: when input is detected as HTML, `MarkdownToHTML` passes it through
verbatim and never runs goldmark, so the Markdown mention link is not converted
to an `<a href="mention:...">` anchor. `resolveMentionAnchors` therefore matched
nothing, and the fuzzy `@Name` pass then matched only the first name token (its
regex stops at the first space), turning that into a chip and leaving the rest of
the link as literal text.

Add a `resolveMentionMarkdownLinks` pass to `ResolveMentions` that recognizes the
literal `[@name](mention:SGID)` / `[@name](person:ID)` form and converts it to a
`<bc-attachment>` mention before the fuzzy pass runs. It reuses the existing
skip guards so links inside `<code>`, existing attachments, or tags (i.e.
documentation) are left untouched. Because the fix lives in the richtext layer,
it covers every call site that composes rich text (comments, messages, cards,
chat, check-ins, documents, todos, schedule).

Reported in card 10088583638.
Copilot AI review requested due to automatic review settings July 13, 2026 14:18
@robzolkos robzolkos force-pushed the fix-mention-link-in-html-block branch from 65853b2 to d8451dd Compare July 13, 2026 14:18
@github-actions github-actions Bot added the bug Something isn't working label Jul 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown

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 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread internal/richtext/richtext.go
Comment thread internal/richtext/richtext.go
Copilot AI review requested due to automatic review settings July 13, 2026 14:57

Copilot AI left a comment

Copy link
Copy Markdown

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 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread internal/richtext/richtext.go

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

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.

No issues found across 2 files

Re-trigger cubic

Copilot AI review requested due to automatic review settings July 13, 2026 15:22

Copilot AI left a comment

Copy link
Copy Markdown

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 2 out of 2 changed files in this pull request and generated no new comments.

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

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.

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread internal/richtext/richtext.go Outdated
Copilot AI review requested due to automatic review settings July 13, 2026 15:39
@robzolkos

Copy link
Copy Markdown
Collaborator Author

Fixed in 1e8c291. Mention exclusion checks now precompute tag, code, pre, and bc-attachment spans once per pass, eliminating the remaining per-match prefix scans.

Copilot AI left a comment

Copy link
Copy Markdown

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 2 out of 2 changed files in this pull request and generated no new comments.

@robzolkos robzolkos merged commit f989b11 into main Jul 13, 2026
27 checks passed
@robzolkos robzolkos deleted the fix-mention-link-in-html-block branch July 13, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working tests Tests (unit and e2e)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants