Convert Markdown mention links inside HTML blocks to mention chips
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) andTestMentionInHTMLBlock_FullPipeline(fullMarkdownToHTML → ResolveMentionssequence 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/cipasses.
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:useslookupByID. - Hardened matching: no cross-tag matches; skip inside
<code>,<pre>, existing<bc-attachment>, or quoted attributes; unescape entities; error onperson:when no lookup is provided.
- Convert literal
-
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 → ResolveMentionspipeline.