1 parent
ab88423a4a
commit
61a2482c48
5 files changed
+904
-6
No files matched your search
@@ -0,0 +1,19 @@
|
||||
#### Handle zero-based lists correctly ([#6852](https://github.com/prettier/prettier/pull/6852) by [@evilebottnawi](https://github.com/evilebottnawi))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```md
|
||||
<!-- Input -->
|
||||
0. List
|
||||
1. List
|
||||
2. List
|
||||
|
||||
<!-- Prettier stable -->
|
||||
0. List
|
||||
1. List
|
||||
1. List
|
||||
|
||||
<!-- Prettier master -->
|
||||
0. List
|
||||
1. List
|
||||
2. List
|
||||
```
|
||||
@@ -25,7 +25,7 @@ const {
|
||||
} = require("../doc");
|
||||
const {
|
||||
getFencedCodeBlockValue,
|
||||
getOrderedListItemInfo,
|
||||
hasGitDiffFriendlyOrderedList,
|
||||
splitText,
|
||||
punctuationPattern,
|
||||
INLINE_NODE_TYPES,
|
||||
@@ -251,11 +251,10 @@ function genericPrint(path, options, print) {
|
||||
path.getParentNode()
|
||||
);
|
||||
|
||||
const isGitDiffFriendlyOrderedList =
|
||||
node.ordered &&
|
||||
node.children.length > 1 &&
|
||||
+getOrderedListItemInfo(node.children[1], options.originalText)
|
||||
.numberText === 1;
|
||||
const isGitDiffFriendlyOrderedList = hasGitDiffFriendlyOrderedList(
|
||||
node,
|
||||
options
|
||||
);
|
||||
|
||||
return printChildren(path, options, print, {
|
||||
processor: (childPath, index) => {
|
||||
|
||||
@@ -162,6 +162,34 @@ function getOrderedListItemInfo(orderListItem, originalText) {
|
||||
return { numberText, marker, leadingSpaces };
|
||||
}
|
||||
|
||||
function hasGitDiffFriendlyOrderedList(node, options) {
|
||||
if (!node.ordered) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (node.children.length < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const firstNumber = Number(
|
||||
getOrderedListItemInfo(node.children[0], options.originalText).numberText
|
||||
);
|
||||
|
||||
const secondNumber = Number(
|
||||
getOrderedListItemInfo(node.children[1], options.originalText).numberText
|
||||
);
|
||||
|
||||
if (firstNumber === 0 && node.children.length > 2) {
|
||||
const thirdNumber = Number(
|
||||
getOrderedListItemInfo(node.children[2], options.originalText).numberText
|
||||
);
|
||||
|
||||
return secondNumber === 1 && thirdNumber === 1;
|
||||
}
|
||||
|
||||
return secondNumber === 1;
|
||||
}
|
||||
|
||||
// workaround for https://github.com/remarkjs/remark/issues/351
|
||||
// leading and trailing newlines are stripped by remark
|
||||
function getFencedCodeBlockValue(node, originalText) {
|
||||
@@ -229,6 +257,7 @@ module.exports = {
|
||||
punctuationPattern,
|
||||
getFencedCodeBlockValue,
|
||||
getOrderedListItemInfo,
|
||||
hasGitDiffFriendlyOrderedList,
|
||||
INLINE_NODE_TYPES,
|
||||
INLINE_NODE_WRAPPER_TYPES
|
||||
};
|
||||
@@ -2458,11 +2458,200 @@ proseWrap: "always"
|
||||
6. def
|
||||
7. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
0. def
|
||||
0. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
2. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
3. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
4. ghi
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
145. def
|
||||
69. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
|
||||
---
|
||||
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
2. def
|
||||
|
||||
=====================================output=====================================
|
||||
5. abc
|
||||
6. def
|
||||
7. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
4. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
3. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
4. ghi
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1000. def
|
||||
1001. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1000. def
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
@@ -2478,11 +2667,200 @@ tabWidth: 4
|
||||
6. def
|
||||
7. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
0. def
|
||||
0. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
2. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
3. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
4. ghi
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
145. def
|
||||
69. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
|
||||
---
|
||||
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
2. def
|
||||
|
||||
=====================================output=====================================
|
||||
5. abc
|
||||
6. def
|
||||
7. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
4. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
3. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
4. ghi
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1000. def
|
||||
1001. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1000. def
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
@@ -2498,11 +2876,200 @@ tabWidth: 999
|
||||
6. def
|
||||
7. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
0. def
|
||||
0. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
2. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
3. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
4. ghi
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
145. def
|
||||
69. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
|
||||
---
|
||||
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
2. def
|
||||
|
||||
=====================================output=====================================
|
||||
5. abc
|
||||
6. def
|
||||
7. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
4. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
3. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
4. ghi
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1000. def
|
||||
1001. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1000. def
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
@@ -2518,10 +3085,199 @@ tabWidth: 0
|
||||
6. def
|
||||
7. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
0. def
|
||||
0. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
2. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
3. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
4. ghi
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
145. def
|
||||
69. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
|
||||
---
|
||||
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
2. def
|
||||
|
||||
=====================================output=====================================
|
||||
5. abc
|
||||
6. def
|
||||
7. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
4. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
3. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
4. ghi
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1000. def
|
||||
1001. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1000. def
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -1,3 +1,98 @@
|
||||
5. abc
|
||||
6. def
|
||||
7. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
0. def
|
||||
0. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
2. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
2. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
3. ghi
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
4. ghi
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
145. def
|
||||
69. ghi
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
|
||||
---
|
||||
|
||||
0. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
1. abc
|
||||
2. def
|
||||
|
||||
---
|
||||
|
||||
|
||||
1. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
2. abc
|
||||
3. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
1. def
|
||||
|
||||
---
|
||||
|
||||
999. abc
|
||||
2. def
|
||||
Reference in new issue
Block a user