--attach stack 3/8: Rewrite markdown references to uploaded assets - #14179
Merged
BagToad merged 2 commits intoAug 25, 2026
Merged
Conversation
--attach stack 3/8: Rewrite markdown references to uploaded assets
BagToad
marked this pull request as ready for review
August 18, 2026 05:56
Contributor
There was a problem hiding this comment.
Pull request overview
Adds internal markdown reference rewriting for uploaded attachments.
Changes:
- Parses and matches attachment references using Goldmark.
- Rewrites image, video, and reference-style destinations.
- Adds comprehensive unit and fixture coverage.
Show a summary per file
| File | Description |
|---|---|
internal/attachments/references.go |
Implements reference scanning and rewriting. |
internal/attachments/references_test.go |
Tests rewriting behavior and edge cases. |
internal/attachments/references_fixture_test.go |
Adds fixture-based regression testing. |
internal/attachments/testdata/references_input.md |
Provides comprehensive fixture input. |
internal/attachments/testdata/references_expected.md |
Defines expected rewritten output. |
Review details
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 5/5 changed files
- Comments generated: 4
- Review effort level: Balanced
Closed
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
BagToad
force-pushed
the
bagtoad/attach-markdown-rewriting
branch
from
August 18, 2026 14:55
9ca0d7e to
2436703
Compare
Closed
9 tasks
babakks
approved these changes
Aug 19, 2026
babakks
left a comment
Member
There was a problem hiding this comment.
Thanks for this one, @BagToad! 🙏
The byte-scanning rewriter is careful work, and the reference-style handling (definitions, collapsed/shortcut forms, code-fence exclusion) covers a lot of tricky ground. I left a batch of comments, but they're all nitpicks, questions, and test-coverage suggestions, nothing blocking.
A few themes:
- One forward-compat nit: the
updatetest flag is quite generic givengo testaccepts many flags, so a more specific name likeupdate-md-fixturewould be safer. - A couple of "four cells" comments left me wondering if some mental grouping didn't make it into the code.
Nothing here needs to hold up the stack. Happy to re-look once you've had a chance to go through them.
babakks
reviewed
Aug 19, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the pull request stack tracked in #14186.
Description
This is the third layer of the stack, and the largest and hardest pull request in it. Nothing here is reachable from a command yet.
Given some markdown and a set of attached files, it finds every reference in the markdown that points at one of those files and rewrites the destination to the uploaded URL. It reports which attachments were never referenced, so the caller can append them.
The code runs in three phases, and it is ordered that way on purpose:
ghalready depends on, and each link or image node is asked for its position.The behaviour that follows from that:
The second commit adds one markdown document that exercises every syntax the package handles, together with its expected output.
How did you test this change?
The whole stack was built and each of the behaviours above was exercised by hand against a private test repository. That covered a reference rewritten in place, a reference style definition with two uses following one edit, a fenced block and an inline code span left untouched, a plain link staying a link, a video alone on a line becoming a bare URL, a video inline becoming a link, a video as a reference style image being refused, an unused definition left alone, a file named in the body but never attached left alone, and the same file referenced twice sharing one uploaded asset.
Key points
About 110 lines of this are hand written byte scanning. It exists because goldmark reports the position of a node but not the position of the destination inside that node.
The alternative would be to re-render the document from the parsed tree. That would be worse, because it normalises the author's own prose, and someone who wrote a comment by hand should get their comment back rather than a reformatted version of it. A follow up can restructure this around goldmark's node identity and delete some of the scanning. That work is not here.
Notes for reviewers
Start with the two entry points and read the three phases in order.
The fixture document in the second commit is the fastest way to understand the behaviour. Reading the input and the expected output side by side shows what the package does without reading the scanner at all, which is why it is a separate commit.
Authorship and follow-up
Who wrote this:
Who answers review comments: