Cap ordered list mark at 999,999,999 (#19351)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
5 files changed
+111
-2
No files matched your search
@@ -0,0 +1,32 @@
|
|||||||
|
#### Cap ordered list mark at 999,999,999 (#19351 by @tats-u)
|
||||||
|
|
||||||
|
CommonMark parsers only support ordered list item numbers up to 999,999,999.
|
||||||
|
|
||||||
|
With this change, Prettier now caps the ordered list item number at 999,999,999 to ensure that the output is correctly parsed as an ordered list by CommonMark parsers. Numbers larger than 999,999,999 are not parsed as list item numbers and are left unchanged in the output:
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
```markdown
|
||||||
|
<!-- Input -->
|
||||||
|
999999998. text
|
||||||
|
999999998. text
|
||||||
|
999999998. text
|
||||||
|
999999998. text
|
||||||
|
|
||||||
|
1234567890123456789012) text
|
||||||
|
|
||||||
|
<!-- Prettier stable -->
|
||||||
|
999999998. text
|
||||||
|
999999999. text
|
||||||
|
1000000000. text
|
||||||
|
1000000001. text
|
||||||
|
|
||||||
|
1234567890123456789012) text
|
||||||
|
|
||||||
|
<!-- Prettier main -->
|
||||||
|
999999998. text
|
||||||
|
999999999. text
|
||||||
|
999999999. text
|
||||||
|
999999999. text
|
||||||
|
|
||||||
|
1234567890123456789012) text
|
||||||
|
```
|
||||||
@@ -10,6 +10,10 @@ import { printChildren } from "./children.js";
|
|||||||
* @import {Doc} from "../../document/index.js"
|
* @import {Doc} from "../../document/index.js"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// 999,999,999 is the maximum number that can be parsed as a list item number as intended in CommonMark
|
||||||
|
// https://spec.commonmark.org/0.31.2/#ordered-list-marker
|
||||||
|
const MAXIMUM_ORDERED_LIST_MARKER = 999_999_999;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {AstPath} path
|
* @param {AstPath} path
|
||||||
* @param {*} options
|
* @param {*} options
|
||||||
@@ -55,8 +59,10 @@ function printList(path, options, print) {
|
|||||||
? node.start
|
? node.start
|
||||||
: isGitDiffFriendlyOrderedList
|
: isGitDiffFriendlyOrderedList
|
||||||
? 1
|
? 1
|
||||||
: node.start + path.index) +
|
: Math.min(
|
||||||
(nthSiblingIndex % 2 === 0 ? ". " : ") ")
|
node.start + path.index,
|
||||||
|
MAXIMUM_ORDERED_LIST_MARKER,
|
||||||
|
)) + (nthSiblingIndex % 2 === 0 ? ". " : ") ")
|
||||||
: nthSiblingIndex % 2 === 0
|
: nthSiblingIndex % 2 === 0
|
||||||
? "- "
|
? "- "
|
||||||
: "* ";
|
: "* ";
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||||
|
|
||||||
|
exports[`huge-first-number.md format 1`] = `
|
||||||
|
====================================options=====================================
|
||||||
|
parsers: ["markdown"]
|
||||||
|
printWidth: 80 (default) |
|
||||||
|
=====================================input======================================
|
||||||
|
999999998. text
|
||||||
|
999999998. text
|
||||||
|
999999998. text
|
||||||
|
999999998. text
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
999999998. text
|
||||||
|
1. text
|
||||||
|
1. text
|
||||||
|
1. text
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
999999998. text
|
||||||
|
1. text
|
||||||
|
2. text
|
||||||
|
3. text
|
||||||
|
|
||||||
|
=====================================output=====================================
|
||||||
|
999999998. text
|
||||||
|
999999999. text
|
||||||
|
999999999. text
|
||||||
|
999999999. text
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
999999998. text
|
||||||
|
1. text
|
||||||
|
1. text
|
||||||
|
1. text
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
999999998. text
|
||||||
|
1. text
|
||||||
|
1. text
|
||||||
|
1. text
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
runFormatTest(import.meta, [
|
||||||
|
"markdown",
|
||||||
|
// Add this parser when closing https://github.com/prettier/prettier/issues/19339
|
||||||
|
// "mdx",
|
||||||
|
]);
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
999999998. text
|
||||||
|
999999998. text
|
||||||
|
999999998. text
|
||||||
|
999999998. text
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
999999998. text
|
||||||
|
1. text
|
||||||
|
1. text
|
||||||
|
1. text
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
999999998. text
|
||||||
|
1. text
|
||||||
|
2. text
|
||||||
|
3. text
|
||||||
Reference in new issue
Block a user