Skip to content

[[foo:bar]] in markdown turns into [[foo]] incorrectly (Prettier v3.9.0 regression) #19525

Description

@YDX-2147483647

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.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!lang:markdownIssues affecting Markdown

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions