Fix indentation drift for indented code blocks in list items (#19990)
Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
1 parent
60600efbb6
commit
018faacfdb
5 files changed
+74
-3
No files matched your search
@@ -1,6 +1,4 @@
|
|||||||
#### Prevent indentation drift in task-list code blocks (#19647 by @Austin1serb)
|
#### Prevent indentation drift in list-item code blocks (#19647, #19990 by @Austin1serb, @giaBaoJS)
|
||||||
|
|
||||||
Indented code blocks inside task-list items no longer gain four spaces on each formatting pass.
|
|
||||||
|
|
||||||
<!-- prettier-ignore -->
|
<!-- prettier-ignore -->
|
||||||
```markdown
|
```markdown
|
||||||
|
|||||||
@@ -103,6 +103,10 @@ function printListItem(path, options, print, listPrefix) {
|
|||||||
return align(" ".repeat(prefix.length), print());
|
return align(" ".repeat(prefix.length), print());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.type === "code" && node.isIndented) {
|
||||||
|
return print();
|
||||||
|
}
|
||||||
|
|
||||||
const alignment = " ".repeat(
|
const alignment = " ".repeat(
|
||||||
clamp(options.tabWidth - listPrefix.length, 0, 3), // 4+ will cause indented code block
|
clamp(options.tabWidth - listPrefix.length, 0, 3), // 4+ will cause indented code block
|
||||||
);
|
);
|
||||||
@@ -208,6 +212,10 @@ function printListItemLegacy(path, options, print, listPrefix) {
|
|||||||
return align(" ".repeat(prefix.length), print());
|
return align(" ".repeat(prefix.length), print());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.type === "code" && node.isIndented) {
|
||||||
|
return print();
|
||||||
|
}
|
||||||
|
|
||||||
const alignment = " ".repeat(
|
const alignment = " ".repeat(
|
||||||
clamp(options.tabWidth - listPrefix.length, 0, 3), // 4+ will cause indented code block
|
clamp(options.tabWidth - listPrefix.length, 0, 3), // 4+ will cause indented code block
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||||
|
|
||||||
|
exports[`indented-code-block.md - {"tabWidth":4} format 1`] = `
|
||||||
|
====================================options=====================================
|
||||||
|
parsers: ["markdown", "mdx"]
|
||||||
|
tabWidth: 4
|
||||||
|
printWidth: 80 (default) |
|
||||||
|
=====================================input======================================
|
||||||
|
- [x] task item
|
||||||
|
|
||||||
|
indented code
|
||||||
|
|
||||||
|
- unordered item
|
||||||
|
|
||||||
|
indented code
|
||||||
|
|
||||||
|
- outer item
|
||||||
|
|
||||||
|
- nested item
|
||||||
|
|
||||||
|
indented code
|
||||||
|
|
||||||
|
- item with extra code indentation
|
||||||
|
|
||||||
|
indented code
|
||||||
|
|
||||||
|
=====================================output=====================================
|
||||||
|
- [x] task item
|
||||||
|
|
||||||
|
indented code
|
||||||
|
|
||||||
|
- unordered item
|
||||||
|
|
||||||
|
indented code
|
||||||
|
|
||||||
|
- outer item
|
||||||
|
|
||||||
|
- nested item
|
||||||
|
|
||||||
|
indented code
|
||||||
|
|
||||||
|
- item with extra code indentation
|
||||||
|
|
||||||
|
indented code
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
runFormatTest(import.meta, ["markdown", "mdx"], { tabWidth: 4 });
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
- [x] task item
|
||||||
|
|
||||||
|
indented code
|
||||||
|
|
||||||
|
- unordered item
|
||||||
|
|
||||||
|
indented code
|
||||||
|
|
||||||
|
- outer item
|
||||||
|
|
||||||
|
- nested item
|
||||||
|
|
||||||
|
indented code
|
||||||
|
|
||||||
|
- item with extra code indentation
|
||||||
|
|
||||||
|
indented code
|
||||||
Reference in new issue
Block a user