Fix extra blank line between a list and an indented code block (#19154)
Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
1 parent
80cdddb79b
commit
f941cb6364
5 files changed
+77
-65
No files matched your search
@@ -0,0 +1,22 @@
|
||||
#### Fix extra blank line between a list and an indented code block (#19154 by @YBJ0000)
|
||||
|
||||
Prettier forced two blank lines whenever an indented code block followed a list. The extra blank line is never semantically required and contradicts Prettier's usual behavior of collapsing consecutive blank lines into a single one.
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```markdown
|
||||
<!-- Input -->
|
||||
- one
|
||||
|
||||
two
|
||||
|
||||
<!-- Prettier stable -->
|
||||
- one
|
||||
|
||||
|
||||
two
|
||||
|
||||
<!-- Prettier main -->
|
||||
- one
|
||||
|
||||
two
|
||||
```
|
||||
@@ -29,14 +29,7 @@ function printChildren(path, options, print, events = {}) {
|
||||
if (parts.length > 0 && shouldPrePrintHardline(path)) {
|
||||
parts.push(hardline);
|
||||
|
||||
if (
|
||||
shouldPrePrintDoubleHardline(path, options) ||
|
||||
shouldPrePrintTripleHardline(path)
|
||||
) {
|
||||
parts.push(hardline);
|
||||
}
|
||||
|
||||
if (shouldPrePrintTripleHardline(path)) {
|
||||
if (shouldPrePrintDoubleHardline(path, options)) {
|
||||
parts.push(hardline);
|
||||
}
|
||||
}
|
||||
@@ -131,13 +124,6 @@ function shouldPrePrintDoubleHardline(path, options) {
|
||||
);
|
||||
}
|
||||
|
||||
function shouldPrePrintTripleHardline({ node, previous }) {
|
||||
const isPrevNodeList = previous.type === "list";
|
||||
const isIndentedCode = node.type === "code" && node.isIndented;
|
||||
|
||||
return isPrevNodeList && isIndentedCode;
|
||||
}
|
||||
|
||||
function isLooseListItemLegacy(node, options) {
|
||||
return (
|
||||
node.type === "listItem" &&
|
||||
|
||||
@@ -4604,7 +4604,6 @@ proseWrap: "always"
|
||||
=====================================output=====================================
|
||||
- one
|
||||
|
||||
|
||||
two
|
||||
|
||||
================================================================================
|
||||
@@ -5686,7 +5685,6 @@ proseWrap: "always"
|
||||
|
||||
2. b
|
||||
|
||||
|
||||
3. c
|
||||
|
||||
================================================================================
|
||||
|
||||
@@ -1175,10 +1175,15 @@ tabWidth: 0
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
|
||||
- one
|
||||
|
||||
two
|
||||
|
||||
=====================================output=====================================
|
||||
- foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1191,7 +1196,6 @@ tabWidth: 0
|
||||
|
||||
- foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1204,7 +1208,6 @@ tabWidth: 0
|
||||
|
||||
1. foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1217,7 +1220,6 @@ tabWidth: 0
|
||||
|
||||
1. foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1230,7 +1232,6 @@ tabWidth: 0
|
||||
|
||||
- [ ] foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1244,7 +1245,6 @@ tabWidth: 0
|
||||
- item 1
|
||||
- item 2
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1261,7 +1261,6 @@ tabWidth: 0
|
||||
- item 1-1
|
||||
- item 1-2
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1271,7 +1270,6 @@ tabWidth: 0
|
||||
- item 1-2
|
||||
- item 2
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1289,7 +1287,6 @@ tabWidth: 0
|
||||
2. item 1-2
|
||||
2. item 1
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1300,7 +1297,6 @@ tabWidth: 0
|
||||
|
||||
text
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1309,12 +1305,16 @@ tabWidth: 0
|
||||
- item 1-1
|
||||
- item 1-2
|
||||
|
||||
|
||||
indented code block
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
|
||||
- one
|
||||
|
||||
two
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
@@ -1453,10 +1453,15 @@ tabWidth: 4
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
|
||||
- one
|
||||
|
||||
two
|
||||
|
||||
=====================================output=====================================
|
||||
- foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1469,7 +1474,6 @@ tabWidth: 4
|
||||
|
||||
- foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1482,7 +1486,6 @@ tabWidth: 4
|
||||
|
||||
1. foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1495,7 +1498,6 @@ tabWidth: 4
|
||||
|
||||
1. foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1508,7 +1510,6 @@ tabWidth: 4
|
||||
|
||||
- [ ] foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1522,7 +1523,6 @@ tabWidth: 4
|
||||
- item 1
|
||||
- item 2
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1539,7 +1539,6 @@ tabWidth: 4
|
||||
- item 1-1
|
||||
- item 1-2
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1549,7 +1548,6 @@ tabWidth: 4
|
||||
- item 1-2
|
||||
- item 2
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1567,7 +1565,6 @@ tabWidth: 4
|
||||
2. item 1-2
|
||||
2. item 1
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1578,7 +1575,6 @@ tabWidth: 4
|
||||
|
||||
text
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1587,12 +1583,16 @@ tabWidth: 4
|
||||
- item 1-1
|
||||
- item 1-2
|
||||
|
||||
|
||||
indented code block
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
|
||||
- one
|
||||
|
||||
two
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
@@ -1731,10 +1731,15 @@ tabWidth: 999
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
|
||||
- one
|
||||
|
||||
two
|
||||
|
||||
=====================================output=====================================
|
||||
- foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1747,7 +1752,6 @@ tabWidth: 999
|
||||
|
||||
- foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1760,7 +1764,6 @@ tabWidth: 999
|
||||
|
||||
1. foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1773,7 +1776,6 @@ tabWidth: 999
|
||||
|
||||
1. foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1786,7 +1788,6 @@ tabWidth: 999
|
||||
|
||||
- [ ] foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1800,7 +1801,6 @@ tabWidth: 999
|
||||
- item 1
|
||||
- item 2
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1817,7 +1817,6 @@ tabWidth: 999
|
||||
- item 1-1
|
||||
- item 1-2
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1827,7 +1826,6 @@ tabWidth: 999
|
||||
- item 1-2
|
||||
- item 2
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1845,7 +1843,6 @@ tabWidth: 999
|
||||
2. item 1-2
|
||||
2. item 1
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1856,7 +1853,6 @@ tabWidth: 999
|
||||
|
||||
text
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -1865,12 +1861,16 @@ tabWidth: 999
|
||||
- item 1-1
|
||||
- item 1-2
|
||||
|
||||
|
||||
indented code block
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
|
||||
- one
|
||||
|
||||
two
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
@@ -2008,10 +2008,15 @@ proseWrap: "always"
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
|
||||
- one
|
||||
|
||||
two
|
||||
|
||||
=====================================output=====================================
|
||||
- foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -2024,7 +2029,6 @@ proseWrap: "always"
|
||||
|
||||
- foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -2037,7 +2041,6 @@ proseWrap: "always"
|
||||
|
||||
1. foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -2050,7 +2053,6 @@ proseWrap: "always"
|
||||
|
||||
1. foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -2063,7 +2065,6 @@ proseWrap: "always"
|
||||
|
||||
- [ ] foo
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -2077,7 +2078,6 @@ proseWrap: "always"
|
||||
- item 1
|
||||
- item 2
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -2094,7 +2094,6 @@ proseWrap: "always"
|
||||
- item 1-1
|
||||
- item 1-2
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -2104,7 +2103,6 @@ proseWrap: "always"
|
||||
- item 1-2
|
||||
- item 2
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -2122,7 +2120,6 @@ proseWrap: "always"
|
||||
2. item 1-2
|
||||
2. item 1
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -2133,7 +2130,6 @@ proseWrap: "always"
|
||||
|
||||
text
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
@@ -2142,12 +2138,16 @@ proseWrap: "always"
|
||||
- item 1-1
|
||||
- item 1-2
|
||||
|
||||
|
||||
indented code block
|
||||
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
|
||||
- one
|
||||
|
||||
two
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
|
||||
@@ -125,3 +125,9 @@
|
||||
indented code block
|
||||
|
||||
top level indented code block
|
||||
|
||||
---
|
||||
|
||||
- one
|
||||
|
||||
two
|
||||
Reference in new issue
Block a user