`[[foo:bar]]` in markdown turns into `[[foo]]` incorrectly (Prettier v3.9.0 regression)
#19,525 建立於 2026年7月2日
倉庫指標
- Star
- (51,868 star)
- PR 合併指標
- (平均合併 6天) (30 天內合併 186 個 PR)
描述
Prettier v3.9.4 Playground link
--parser markdown
Input:
[[Help:Link]]
Output:
[[Help]]
Expected output:
[[Help:Link]]
Why?
The support for [[wiki-style]] links (aka. wiki-link, wikitext link) was added in #9275 since Prettier v2.2.0.
Links in wikitext can have a namespace prefix ended with a colon (:). For example, [[Help:Link]] means the page Link under the namespace Help:.
(Refer to Help:Link - Wikipedia or Wikipedia:Namespace - Wikipedia for the details.)
Prettier v3.8.1 and v3.8.5 could format [[Help:Link]] correctly (by keeping it as is).
However, Prettier v3.9.0 changed the markdown parser from remark-parse to micromark in #18277.
It looks like that the new parser uses micromark-extension-wiki-link (v0.0.4, published in 2021 by landakram) and mdast-util-wiki-link (v0.1.2, published in 2023 by the same author) to parse wikitext links.
These two packages somehow think colons mean aliases. They parse [[Real Page:Page Alias]] as { value: "Real Page", data: { alias: "Page Alias" } } or <a href="path/to/Real Page">Page Alias</a>.
Unfortunately, Prettier v3.9.0 and v3.9.4 just ignore data.alias, leading to the loss of information.
https://github.com/prettier/prettier/blob/cf7db3500a89faeb24ad0af45c6b9a0e7b074a03/src/language-markdown/print/mdast.js#L197-L206
In fact the real wikitext link uses [[Real Page|Page Alias]] for this purpose.
But in any case, Prettier should keep the part after the colon.