Prettier v3.9.4
Playground link
Input:
Output:
Expected output:
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.
|
case "wikiLink": { |
|
let contents; |
|
if (options.proseWrap === "preserve") { |
|
contents = node.value; |
|
} else { |
|
contents = node.value.replaceAll(/[\t\n]+/g, " "); |
|
} |
|
|
|
return ["[[", contents, "]]"]; |
|
} |
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.
Prettier v3.9.4
Playground link
Input:
Output:
Expected output:
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 pageLinkunder the namespaceHelp:.(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-parsetomicromarkin #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.prettier/src/language-markdown/print/mdast.js
Lines 197 to 206 in cf7db35
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.