Skip to content

Commit d45a881

Browse files
keep nested emphasis around an autolink from turning into strong
an emphasis that starts with an autolink keeps the delimiter it was written with . the emphasis around it did not know that and picked `_` too , so `*_https://a.b_*` came out as `__https://a.b__` , which is strong emphasis , and the next format turned it into `**https://a.b**` . the parent now keeps its written delimiter as well . the issue case is pinned in emphasis/issue-8654.md . 18 of the 24 nested wrappers commented out in the auto-link test pass now and are turned back on , 4 of their cases fail on main . the other 6 wrappers still fail the same way on main for a different reason and stay commented out . Co-Authored-By: Claude Opus 5 <[email protected]>
1 parent 1a36a7d commit d45a881

6 files changed

Lines changed: 4153 additions & 426 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#### Keep nested emphasis around an autolink from turning into strong emphasis (#20128 by @HuzaifaChaudary)
2+
3+
<!-- prettier-ignore -->
4+
```md
5+
<!-- Input -->
6+
Read *_https://example.com_* first.
7+
8+
<!-- Prettier stable (First format) -->
9+
Read __https://example.com__ first.
10+
11+
<!-- Prettier stable (Second format) -->
12+
Read **https://example.com** first.
13+
14+
<!-- Prettier main -->
15+
Read *_https://example.com_* first.
16+
```

‎src/language-markdown/print/mdast.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,13 @@ function printMdast(path, options, print) {
113113
return printWhitespaceNode(path, options);
114114
case "emphasis": {
115115
let style;
116-
if (isAutolink(node.children[0])) {
116+
const [firstChild] = node.children;
117+
if (
118+
isAutolink(firstChild) ||
119+
// The inner emphasis keeps its delimiter, so changing this one can
120+
// turn `*_https://a.b_*` into `__https://a.b__`, which is strong
121+
(firstChild.type === "emphasis" && isAutolink(firstChild.children[0]))
122+
) {
117123
style = options.originalText[node.position.start.offset];
118124
} else {
119125
const hasPrevOrNextWord = prevOrNextWord(path); // `1*2*3` is considered emphasis but `1_2_3` is not

0 commit comments

Comments
 (0)