Fix markdown newline removal for CJK list-marker false positive (#18867)
This commit is contained in:
1 parent
1038b1231b
commit
70c3c2b4f6
4 files changed
+57
-1
No files matched your search
@@ -0,0 +1,20 @@
|
||||
#### Fix CJK line break loss near list-like numbers (#18867 by @it-education-md)
|
||||
|
||||
Avoid collapsing line breaks before list-like numbers followed by CJK characters (e.g. 3.中).
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```markdown
|
||||
<!-- Input -->
|
||||
1.a
|
||||
2.b
|
||||
3.中
|
||||
|
||||
<!-- Prettier stable -->
|
||||
1.a
|
||||
2.b 3.中
|
||||
|
||||
<!-- Prettier main -->
|
||||
1.a
|
||||
2.b
|
||||
3.中
|
||||
```
|
||||
@@ -52,6 +52,15 @@ function prevOrNextWord(path) {
|
||||
return hasPrevOrNextWord;
|
||||
}
|
||||
|
||||
function hasFakeWhitespaceAfterNextToken(path) {
|
||||
const { siblings, index } = path;
|
||||
if (!siblings || typeof index !== "number") {
|
||||
return false;
|
||||
}
|
||||
const afterNext = siblings[index + 2];
|
||||
return afterNext?.type === "whitespace" && afterNext.value === "";
|
||||
}
|
||||
|
||||
function printMdast(path, options, print) {
|
||||
const { node } = path;
|
||||
|
||||
@@ -109,7 +118,10 @@ function printMdast(path, options, print) {
|
||||
|
||||
const proseWrap =
|
||||
// leading char that may cause different syntax
|
||||
next && /^>|^(?:[*+-]|#{1,6}|\d+[).])$/.test(next.value)
|
||||
next &&
|
||||
/^>|^(?:[*+-]|#{1,6}|\d+[).])$/.test(next.value) &&
|
||||
// Avoid https://github.com/prettier/prettier/issues/18861
|
||||
!hasFakeWhitespaceAfterNextToken(path)
|
||||
? "never"
|
||||
: options.proseWrap;
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ IVS 麻󠄁羽󠄀‼️
|
||||
|
||||
⿰あ⿱あ⿲あ⿳あ⿴あ⿵あ⿶あ⿷あ⿸あ⿹あ⿺あ⿻あ
|
||||
|
||||
1.a
|
||||
2.b
|
||||
3.中
|
||||
|
||||
=====================================output=====================================
|
||||
這是一段很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長的段落
|
||||
|
||||
@@ -45,6 +49,8 @@ IVS 麻󠄁羽󠄀‼️
|
||||
|
||||
⿰あ⿱あ⿲あ⿳あ⿴あ⿵あ⿶あ⿷あ⿸あ⿹あ⿺あ⿻あ
|
||||
|
||||
1.a 2.b 3.中
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
@@ -74,6 +80,10 @@ IVS 麻󠄁羽󠄀‼️
|
||||
|
||||
⿰あ⿱あ⿲あ⿳あ⿴あ⿵あ⿶あ⿷あ⿸あ⿹あ⿺あ⿻あ
|
||||
|
||||
1.a
|
||||
2.b
|
||||
3.中
|
||||
|
||||
=====================================output=====================================
|
||||
這是一段很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長的段落
|
||||
|
||||
@@ -93,6 +103,8 @@ IVS 麻󠄁羽󠄀‼️
|
||||
|
||||
⿰あ⿱あ⿲あ⿳あ⿴あ⿵あ⿶あ⿷あ⿸あ⿹あ⿺あ⿻あ
|
||||
|
||||
1.a 2.b 3.中
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
@@ -122,6 +134,10 @@ IVS 麻󠄁羽󠄀‼️
|
||||
|
||||
⿰あ⿱あ⿲あ⿳あ⿴あ⿵あ⿶あ⿷あ⿸あ⿹あ⿺あ⿻あ
|
||||
|
||||
1.a
|
||||
2.b
|
||||
3.中
|
||||
|
||||
=====================================output=====================================
|
||||
這是一段很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長的段落
|
||||
|
||||
@@ -143,6 +159,10 @@ IVS 麻󠄁羽󠄀‼️
|
||||
|
||||
⿰あ⿱あ⿲あ⿳あ⿴あ⿵あ⿶あ⿷あ⿸あ⿹あ⿺あ⿻あ
|
||||
|
||||
1.a
|
||||
2.b
|
||||
3.中
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
|
||||
@@ -17,3 +17,7 @@ This ia an english paragraph with a CJK quote “中文“.
|
||||
IVS 麻󠄁羽󠄀‼️
|
||||
|
||||
⿰あ⿱あ⿲あ⿳あ⿴あ⿵あ⿶あ⿷あ⿸あ⿹あ⿺あ⿻あ
|
||||
|
||||
1.a
|
||||
2.b
|
||||
3.中
|
||||
Reference in new issue
Block a user