Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added 'orderedListMarker' option #6625

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/common/common-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,29 @@ module.exports = {
{ value: false, deprecated: "1.9.0", redirect: "never" },
{ value: true, deprecated: "1.9.0", redirect: "always" }
]
},
orderedListMarker: {
since: "1.19.0",
category: CATEGORY_COMMON,
type: "choice",
default: "auto",
description: "Type of markers for oredered list.",
choices: [
{
since: "1.19.0",
value: "order",
description: "Use oredered numbers as markers for ordered list."
},
{
since: "1.19.0",
value: "one",
description: "Use 1 as marker for ordered list."
},
{
since: "1.19.0",
value: "auto",
description: "Auto marker depend on content."
}
]
}
};
1 change: 1 addition & 0 deletions src/language-markdown/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const commonOptions = require("../common/common-options");

// format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
module.exports = {
orderedListMarker: commonOptions.orderedListMarker,
proseWrap: commonOptions.proseWrap,
singleQuote: commonOptions.singleQuote
};
29 changes: 19 additions & 10 deletions src/language-markdown/printer-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,25 @@ function genericPrint(path, options, print) {
]);

function getPrefix() {
const rawPrefix = node.ordered
? (index === 0
? node.start
: isGitDiffFriendlyOrderedList
? 1
: node.start + index) +
(nthSiblingIndex % 2 === 0 ? ". " : ") ")
: nthSiblingIndex % 2 === 0
? "- "
: "* ";
let rawPrefix;
if (node.ordered) {
if (index === 0) {
rawPrefix = node.start;
} else {
if (options.orderedListMarker === "order") {
rawPrefix = node.start + index;
} else if (options.orderedListMarker === "one") {
rawPrefix = 1;
} else if (options.orderedListMarker === "auto") {
rawPrefix = isGitDiffFriendlyOrderedList
? 1
: node.start + index;
}
}
rawPrefix += nthSiblingIndex % 2 === 0 ? ". " : ") ";
} else {
rawPrefix = nthSiblingIndex % 2 === 0 ? "- " : "* ";
}

return node.isAligned ||
/* workaround for https://github.com/remarkjs/remark/issues/315 */ node.hasIndentedCodeblock
Expand Down
6 changes: 6 additions & 0 deletions tests_integration/__tests__/__snapshots__/early-exit.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ Format options:
Defaults to false.
--jsx-single-quote Use single quotes in JSX.
Defaults to false.
--ordered-list-marker <order|one|auto>
Type of markers for oredered list.
Defaults to auto.
--parser <flow|babel|babel-flow|typescript|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc>
Which parser to use.
--print-width <int> The line length where Prettier will try wrap.
Expand Down Expand Up @@ -228,6 +231,9 @@ Format options:
Defaults to false.
--jsx-single-quote Use single quotes in JSX.
Defaults to false.
--ordered-list-marker <order|one|auto>
Type of markers for oredered list.
Defaults to auto.
--parser <flow|babel|babel-flow|typescript|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc>
Which parser to use.
--print-width <int> The line length where Prettier will try wrap.
Expand Down
19 changes: 19 additions & 0 deletions tests_integration/__tests__/__snapshots__/help-options.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,25 @@ exports[`show detailed usage with --help no-semi (stdout) 1`] = `

exports[`show detailed usage with --help no-semi (write) 1`] = `Array []`;

exports[`show detailed usage with --help ordered-list-marker (stderr) 1`] = `""`;

exports[`show detailed usage with --help ordered-list-marker (stdout) 1`] = `
"--ordered-list-marker <order|one|auto>

Type of markers for oredered list.

Valid options:

order Use oredered numbers as markers for ordered list.
one Use 1 as marker for ordered list.
auto Auto marker depend on content.

Default: auto
"
`;

exports[`show detailed usage with --help ordered-list-marker (write) 1`] = `Array []`;

exports[`show detailed usage with --help parser (stderr) 1`] = `""`;

exports[`show detailed usage with --help parser (stdout) 1`] = `
Expand Down
1 change: 1 addition & 0 deletions website/playground/Playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const ENABLED_OPTIONS = [
"arrowParens",
"trailingComma",
"proseWrap",
"orderedListMarker",
"htmlWhitespaceSensitivity",
"insertPragma",
"requirePragma",
Expand Down