Send mentions and files back bare when rich text is edited
Editing a post that has an @mention or an image in it corrupts the post. Basecamp returns each mention and file attachment expanded, with an avatar or preview <figure> inside the <bc-attachment> and, for a mention, its rendered HTML in a content attribute. When an agent reads a post, changes some words and sends the content back, Basecamp stores that figure as content of its own. The figure breaks the paragraph around the mention apart, and every edit adds another copy.
richTextToHTML, which every rich-text write goes through, now reduces each <bc-attachment> that names a record (it has an sgid) to the bare tag that the rich text docs say to write. It drops the inner HTML and the content attribute and keeps the tag's other attributes, such as caption. This applies with --format html as well as with Markdown. In Markdown, an attachment written inside a code span or code block is left alone. An attachment without an sgid, such as a horizontal rule, carries its own content and is also left alone.
Fixes #905
Verification
TestCommentsUpdateCollapsesAMentionCopiedFromTheAPIfails onmainin both formats and passes with this change. New unit tests ininternal/richtext/attachments_test.gocover file attributes, attachments without ansgid, and code in Markdown.- Tested against a local bc3: create a message with a mention, then edit it twice by sending back the
contentthatmessages showreturned, once with--format htmland once with Markdown.
| Build | After the HTML edit | After the Markdown edit |
|---|---|---|
| v0.30.0 | 2 figures | 3 figures, paragraph split in two |
| this branch | 1 figure | 1 figure, one paragraph |
The same test with an uploaded image instead of a mention gave the same result on both builds: v0.30.0 corrupts the post and this branch keeps it intact. The image's attributes come through the edits unchanged.
bin/cipasses.
The root cause is on the server, which accepts the expanded form. A server-side fix would cover every API client, but this PR is limited to the CLI.
Summary by cubic
Fixes editing a post with an @mention or file attachment corrupting it by sending the bare <bc-attachment> tag back instead of the expanded form Basecamp returns.
richTextToHTML now reduces every <bc-attachment> naming a record to the write form Basecamp documents, in both HTML and Markdown. It drops the inner <figure> and content attribute but keeps others like caption and filename. Tags are read with an HTML tokenizer and the Markdown parser, so tags inside comments, code, backslash escapes, attribute values, or that are self-closing or unclosed are left as written. A new test covers a tag split across blockquote lines, which must be read from the parser's segments to keep each line's > out of the tag. Fixes #905.