feat(markdown): auto-detect which number style of ordered list to be used (#3029)
This commit is contained in:
1 parent
c4118edbe7
commit
c3b965145b
5 files changed
+34
-7
No files matched your search
+14
-1
@@ -175,10 +175,23 @@ function genericPrint(path, options, print) {
|
||||
node,
|
||||
path.getParentNode()
|
||||
);
|
||||
|
||||
const isGitDiffFriendlyOrderedList =
|
||||
node.ordered &&
|
||||
node.children.length > 1 &&
|
||||
/^\s*1(\.|\))/.test(
|
||||
options.originalText.slice(
|
||||
node.children[1].position.start.offset,
|
||||
node.children[1].position.end.offset
|
||||
)
|
||||
);
|
||||
|
||||
return printChildren(path, options, print, {
|
||||
processor: (childPath, index) => {
|
||||
const prefix = node.ordered
|
||||
? (index === 0 ? node.start : 1) +
|
||||
? (index === 0
|
||||
? node.start
|
||||
: isGitDiffFriendlyOrderedList ? 1 : node.start + index) +
|
||||
(nthSiblingIndex % 2 === 0 ? ". " : ") ")
|
||||
: nthSiblingIndex % 2 === 0 ? "* " : "- ";
|
||||
return concat([prefix, align(prefix.length, childPath.call(print))]);
|
||||
|
||||
@@ -2243,7 +2243,7 @@ This is a paragraph.
|
||||
> ## This is a header.
|
||||
>
|
||||
> 1. This is the first list item.
|
||||
> 1. This is the second list item.
|
||||
> 2. This is the second list item.
|
||||
>
|
||||
> Here's some example code:
|
||||
>
|
||||
|
||||
@@ -11,6 +11,17 @@ exports[`checkbox.md 1`] = `
|
||||
|
||||
`;
|
||||
|
||||
exports[`git-diff-friendly.md 1`] = `
|
||||
5. abc
|
||||
1. def
|
||||
999. ghi
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
5. abc
|
||||
1. def
|
||||
1. ghi
|
||||
|
||||
`;
|
||||
|
||||
exports[`long-paragraph.md 1`] = `
|
||||
- This is a long long long long long long long long long long long long long long paragraph.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
@@ -113,7 +124,7 @@ exports[`start.md 1`] = `
|
||||
7. ghi
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
5. abc
|
||||
1. def
|
||||
1. ghi
|
||||
6. def
|
||||
7. ghi
|
||||
|
||||
`;
|
||||
@@ -0,0 +1,3 @@
|
||||
5. abc
|
||||
1. def
|
||||
999. ghi
|
||||
@@ -2765,8 +2765,8 @@ exports[`example-243.md 1`] = `
|
||||
3. bar
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
1. foo
|
||||
1.
|
||||
1. bar
|
||||
2.
|
||||
3. bar
|
||||
|
||||
`;
|
||||
|
||||
@@ -2967,7 +2967,7 @@ exports[`example-261.md 1`] = `
|
||||
3) baz
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
1. foo
|
||||
1. bar
|
||||
2. bar
|
||||
|
||||
3) baz
|
||||
|
||||
|
||||
Reference in new issue
Block a user