fix: prevent underscore emphasis in wikilink image filenames#2306
Open
kanaupi wants to merge 1 commit into
Open
fix: prevent underscore emphasis in wikilink image filenames#2306kanaupi wants to merge 1 commit into
kanaupi wants to merge 1 commit into
Conversation
Image wikilinks like `![[my_photo_2024.png]]` are broken when the textTransform phase re-emits them as raw text, because the Markdown parser interprets `_photo_` as emphasis (`<em>photo</em>`), destroying the wikilink syntax before it can be resolved to an `<img>` tag. Convert image embeds (`![[…]]`) with recognised image extensions to standard Markdown image syntax with angle-bracket destinations (``) early in the textTransform callback, so the Markdown parser sees a proper image node instead of raw text with underscores. Fixes jackyzha0#2291 Co-authored-by: Cursor <[email protected]>
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
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.
Summary
Fixes #2305
Image wikilinks like
![[my_photo_2024-01-01_overview_(1).jpg]]fail to render as<img>tags because the Markdown parser interprets_text_patterns in the filename as emphasis, fragmenting the wikilink text across multiple mdast nodes beforemdastFindReplacecan match and convert it.This PR modifies the existing
textTransformwikilink handler inofm.tsto convert image embeds to standard Markdown image syntax with angle-bracket destinations (), which preserves underscores verbatim through the Markdown parser.Root cause
The processing pipeline in
ofm.ts:textTransform— recognizes![[file.jpg]]viawikilinkRegex, but re-emits it as raw![[file.jpg]]text_text_patterns inside[[...]]becomeemphasisnodes, splitting the wikilink textmarkdownPlugins/mdastFindReplace— can no longer match the wikilink regex because the text is fragmented by emphasis nodesFix
In the
textTransformphase where image wikilinks are already identified bywikilinkRegex, convert them to standard Markdown image syntax:The angle-bracket destination syntax is part of the CommonMark spec and prevents the Markdown parser from interpreting underscores as emphasis.
CrawlLinksresolves the image path from the resultingimagenode as usual.Non-image embeds (video, audio, PDF, transclusion) remain as wikilinks for the existing
markdownPluginshandling.Test plan
![[my_photo_2024.png]])![[photo.png|alt text]])