ENG-2217 Rewrite asset links in Obsidian-origin markdown for Roam - #1398
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
1b550fd to
4ce0832
Compare
4ce0832 to
2950a2a
Compare
2950a2a to
28e9eaa
Compare
28e9eaa to
7bb3b3d
Compare
7bb3b3d to
1179bdb
Compare
1179bdb to
e0588dd
Compare
PR size/scope checkThis PR is over our review-size guideline.
Please split this into smaller PRs unless there is a clear reason the changes need to land together. If keeping it as one PR, please add a brief justification covering:
|
There was a problem hiding this comment.
Note
This report is out of date. Scroll down for Devin Review's latest report on this PR.
Devin Review found 4 potential issues.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| return markdown.replace( | ||
| LINK_PATTERN, | ||
| // One capture group per branch, in the order the pattern lists them. The trailing | ||
| // offset and input arguments the replacer also receives are simply not destructured. | ||
| (match: string, ...groups: (string | undefined)[]) => { |
There was a problem hiding this comment.
🟡 Code examples become live assets
When markdown demonstrates a recorded asset inside code, replace rewrites that example too. The imported page no longer preserves its source text.
Learn more
Make rewriteAssetLinks syntax-aware so replacements occur only in markdown link and embed nodes, not inside inline code, fenced code blocks, or other literal markdown regions. A markdown parser is preferable to expanding the global regular expression. Add cases where the same sourceRef appears once as an actual embed and once inside inline and fenced code.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
This is accurate, but solving it expands the scope considerably. Proposing to punt.
Written as an issue candidate in Roam.
e0588dd to
0f5a93e
Compare
0f5a93e to
c1d603a
Compare
ef15f98 to
349c0e0
Compare
349c0e0 to
0f71a67
Compare
0f71a67 to
f225e53
Compare
f225e53 to
d77dd2c
Compare
d77dd2c to
0f834a4
Compare
0f834a4 to
e3c12d5
Compare
e3c12d5 to
a37d0c0
Compare
a37d0c0 to
b94dd69
Compare
b94dd69 to
f2ce51a
Compare
|
Added two commits, to handle two more cases. Those all fall into the original scope of "Find asset references in the markdown", and were just missed in first implementation. |
There was a problem hiding this comment.
Devin Review found 2 new potential issues.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| // A wikilink embed carries no separate text, so its label comes from the asset. | ||
| linkText: imageLocator ? (imageAlt ?? "") : (linkLabel ?? wikiLabel ?? ""), |
There was a problem hiding this comment.
🟡 Unaliased wikilinks become media embeds
parseMatch gives [[image.png]] no link text, so render treats the link like an embed. The imported page embeds media instead of preserving the source link.
Learn more
An Obsidian wikilink without an alias still has visible link text derived from its target. The parser currently represents that text as empty. The early link-preservation branch then does not run, and the resolved extension selects an image, PDF, audio, or video embed.
Example: [[attachments/diagram.png]] is a normal link to an image file. After resolution, it becomes  rather than a link such as diagram.png.
Recommended fix: Distinguish unaliased wikilinks from genuinely empty Markdown links. Supply their implicit display text to render, or add an explicit wikilink form whose media rendering always remains a link.
Was this helpful? React with 👍 or 👎 to provide feedback.
| return markdown.replace( | ||
| LINK_PATTERN, |
There was a problem hiding this comment.
🟡 Code examples silently change
rewriteAssetLinks applies LINK_PATTERN inside fenced and inline code when a matching asset exists. Literal examples then contain destination URLs instead of the published text.
Learn more
Markdown code spans and fenced code blocks treat link syntax as literal text. A regex over the complete document cannot distinguish those regions from rendered links. If the same locator appears as a real asset elsewhere, the map contains a matching row and the literal occurrence changes too.
Example: A note embeds ![[diagram.png]] and later documents that syntax inside a fenced block. Both occurrences become Firebase syntax, although the fenced example must remain ![[diagram.png]].
Recommended fix: Parse the markdown into syntax nodes and rewrite only link, image, and supported embed nodes. If the existing regex remains, first segment the document with a Markdown-aware tokenizer and exclude code spans and fenced code blocks from replacement.
Was this helpful? React with 👍 or 👎 to provide feedback.

Reviewer brief
Given a markdown and assets, rewrite the links to use the firebase links.
We have to look up the file type to make the right kind of Roam link; since Obsidian does not have distinct link shapes, we have to infer from mimetype or file extension.
Verification
Unit tests. Real tests in the next PR.
Loom video
https://www.loom.com/share/ac85dc0a4df9411c84858e965dadb86f
Note: I did push a refactor from 2219 to 2217 after the loom, but no behaviour change.
I also renamed Token, which was ambiguous, to Locator.
Scope check
$scope-checkagainst ENG-2217 and the final diff.Done When: Addsmime-db(+@types/mime-db) as anapps/roamdependency.Done Whenrequires correct Roam syntax per media type, and the type set is not enumerable by hand: the extension table is derived from all ~1000mime-dbtypes (223 extensions) so an imported asset renders as the same file would if uploaded natively. Cost:db.jsonis not tree-shakeable, so ~204 KB lands inextension.js(23KB compressed); a build-time codegen of the table would remove it later.EXTENSION_KINDSdocstring; no Linear decision.Local delegated full review
$dg-delegated-full-reviewwhen no other full-review workflow is available.https://linear.app/discourse-graphs/issue/ENG-2217/rewrite-asset-links-in-obsidian-origin-markdown-for-roam