Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: prevent underscore emphasis in wikilink image filenames#2306

Open
kanaupi wants to merge 1 commit into
jackyzha0:v4from
kanaupi:fix/wikilink-image-underscore-emphasis
Open

fix: prevent underscore emphasis in wikilink image filenames#2306
kanaupi wants to merge 1 commit into
jackyzha0:v4from
kanaupi:fix/wikilink-image-underscore-emphasis

Conversation

@kanaupi
Copy link
Copy Markdown

@kanaupi kanaupi commented Feb 15, 2026

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 before mdastFindReplace can match and convert it.

This PR modifies the existing textTransform wikilink handler in ofm.ts to convert image embeds to standard Markdown image syntax with angle-bracket destinations (![alt](<filename>)), which preserves underscores verbatim through the Markdown parser.

Root cause

The processing pipeline in ofm.ts:

  1. textTransform — recognizes ![[file.jpg]] via wikilinkRegex, but re-emits it as raw ![[file.jpg]] text
  2. remark parser — parses the text into mdast; _text_ patterns inside [[...]] become emphasis nodes, splitting the wikilink text
  3. markdownPlugins / mdastFindReplace — can no longer match the wikilink regex because the text is fragmented by emphasis nodes

Fix

In the textTransform phase where image wikilinks are already identified by wikilinkRegex, convert them to standard Markdown image syntax:

![[file_name_(1).jpg]]       →  ![](<file_name_(1).jpg>)
![[file_name_(1).jpg|alt]]   →  ![alt](<file_name_(1).jpg>)

The angle-bracket destination syntax is part of the CommonMark spec and prevents the Markdown parser from interpreting underscores as emphasis. CrawlLinks resolves the image path from the resulting image node as usual.

Non-image embeds (video, audio, PDF, transclusion) remain as wikilinks for the existing markdownPlugins handling.

Test plan

  • Image wikilinks with underscores render correctly (e.g. ![[my_photo_2024.png]])
  • Image wikilinks without underscores still render correctly
  • Image wikilinks with aliases render correctly (e.g. ![[photo.png|alt text]])
  • Non-image embeds (video, PDF, transclusion) are unaffected
  • Images inside callouts render correctly

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
(`![alt](<filename>)`) 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]>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 15, 2026

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
quartz ✅ Ready (View Log) Visit Preview 7caddf6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image wikilink embeds with underscores in filename fail to render

1 participant