feat(markdown): add `--no-prose-wrap` option (#3199)
* feat(markdown): add `--no-prose-wrap` option * refactor: fix typo * refactor: fix typo * refactor: reduce duplicate code * docs: mention the option is for markdownmaster
parent
a3ddcb65d2
commit
4f1a2c4108
|
@ -219,6 +219,13 @@ const detailedOptions = normalizeDetailedOptions({
|
|||
forwardToApi: true,
|
||||
description: "The line length where Prettier will try wrap."
|
||||
},
|
||||
"prose-wrap": {
|
||||
type: "boolean",
|
||||
category: CATEGORY_FORMAT,
|
||||
forwardToApi: true,
|
||||
description: "Wrap prose if it exceeds the print width. (markdown)",
|
||||
oppositeDescription: "Do not wrap prose. (markdown)"
|
||||
},
|
||||
"range-end": {
|
||||
type: "int",
|
||||
category: CATEGORY_EDITOR,
|
||||
|
|
|
@ -20,7 +20,8 @@ const defaults = {
|
|||
parser: "babylon",
|
||||
insertPragma: false,
|
||||
requirePragma: false,
|
||||
semi: true
|
||||
semi: true,
|
||||
proseWrap: true
|
||||
};
|
||||
|
||||
const exampleConfig = Object.assign({}, defaults, {
|
||||
|
|
|
@ -60,7 +60,7 @@ function genericPrint(path, options, print) {
|
|||
node =>
|
||||
node.type === "word"
|
||||
? node.value
|
||||
: node.value === "" ? "" : printLine(path, line)
|
||||
: node.value === "" ? "" : printLine(path, line, options)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ function genericPrint(path, options, print) {
|
|||
return node.value === "" ? "" : " ";
|
||||
}
|
||||
|
||||
return printLine(path, node.value === "" ? softline : line);
|
||||
return printLine(path, node.value === "" ? softline : line, options);
|
||||
}
|
||||
case "emphasis": {
|
||||
const parentNode = path.getParentNode();
|
||||
|
@ -125,7 +125,7 @@ function genericPrint(path, options, print) {
|
|||
case "inlineCode": {
|
||||
const backtickCount = util.getMaxContinuousCount(node.value, "`");
|
||||
const style = backtickCount === 1 ? "``" : "`";
|
||||
const gap = backtickCount ? printLine(path, line) : "";
|
||||
const gap = backtickCount ? printLine(path, line, options) : "";
|
||||
return concat([
|
||||
style,
|
||||
gap,
|
||||
|
@ -354,8 +354,9 @@ function getAncestorNode(path, typeOrTypes) {
|
|||
return counter === -1 ? null : path.getParentNode(counter);
|
||||
}
|
||||
|
||||
function printLine(path, lineOrSoftline) {
|
||||
const isBreakable = !getAncestorNode(path, SINGLE_LINE_NODE_TYPES);
|
||||
function printLine(path, lineOrSoftline, options) {
|
||||
const isBreakable =
|
||||
options.proseWrap && !getAncestorNode(path, SINGLE_LINE_NODE_TYPES);
|
||||
return lineOrSoftline === line
|
||||
? isBreakable ? line : " "
|
||||
: isBreakable ? softline : "";
|
||||
|
|
|
@ -26,6 +26,21 @@ English 混合著中文的一段 Paragraph!
|
|||
|
||||
`;
|
||||
|
||||
exports[`cjk.md 2`] = `
|
||||
這是一段很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長的段落
|
||||
|
||||
這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!這是一個English混合著中文的一段Paragraph!
|
||||
|
||||
全 形 空白全 形 空白全 形 空白全 形 空白全 形 空白全 形 空白全 形 空白全 形 空白
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
這是一段很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長的段落
|
||||
|
||||
這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!這是一個 English 混合著中文的一段 Paragraph!
|
||||
|
||||
全 形 空白全 形 空白全 形 空白全 形 空白全 形 空白全 形 空白全 形 空白全 形 空白
|
||||
|
||||
`;
|
||||
|
||||
exports[`inline-nodes.md 1`] = `
|
||||
It removes all original styling[*](#styling-footnote) and ensures that all outputted code conforms to a consistent style. (See this [blog post](http://jlongster.com/A-Prettier-Formatter))
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -35,6 +50,13 @@ post](http://jlongster.com/A-Prettier-Formatter))
|
|||
|
||||
`;
|
||||
|
||||
exports[`inline-nodes.md 2`] = `
|
||||
It removes all original styling[*](#styling-footnote) and ensures that all outputted code conforms to a consistent style. (See this [blog post](http://jlongster.com/A-Prettier-Formatter))
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
It removes all original styling[\\*](#styling-footnote) and ensures that all outputted code conforms to a consistent style. (See this [blog post](http://jlongster.com/A-Prettier-Formatter))
|
||||
|
||||
`;
|
||||
|
||||
exports[`simple.md 1`] = `
|
||||
This is a long long long long long long long long long long long long long long long paragraph.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -43,6 +65,13 @@ long paragraph.
|
|||
|
||||
`;
|
||||
|
||||
exports[`simple.md 2`] = `
|
||||
This is a long long long long long long long long long long long long long long long paragraph.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
This is a long long long long long long long long long long long long long long long paragraph.
|
||||
|
||||
`;
|
||||
|
||||
exports[`special-prefix.md 1`] = `
|
||||
abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc - abc abc abc
|
||||
|
||||
|
@ -90,3 +119,45 @@ abc - abc abc abc
|
|||
ensure expect is called correctly.
|
||||
|
||||
`;
|
||||
|
||||
exports[`special-prefix.md 2`] = `
|
||||
abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc - abc abc abc
|
||||
|
||||
## Supported Rules
|
||||
|
||||
- [no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md) - disallow disabled tests.
|
||||
- [no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md) - disallow focused tests.
|
||||
- [no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md) - disallow identical titles.
|
||||
- [valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md) - ensure expect is called correctly.
|
||||
|
||||
## Supported Rules
|
||||
|
||||
* [no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md)
|
||||
- disallow disabled tests.
|
||||
* [no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md)
|
||||
- disallow focused tests.
|
||||
* [no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md)
|
||||
- disallow identical titles.
|
||||
* [valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md) -
|
||||
ensure expect is called correctly.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc - abc abc abc
|
||||
|
||||
## Supported Rules
|
||||
|
||||
* [no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md) - disallow disabled tests.
|
||||
* [no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md) - disallow focused tests.
|
||||
* [no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md) - disallow identical titles.
|
||||
* [valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md) - ensure expect is called correctly.
|
||||
|
||||
## Supported Rules
|
||||
|
||||
* [no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md)
|
||||
* disallow disabled tests.
|
||||
* [no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md)
|
||||
* disallow focused tests.
|
||||
* [no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md)
|
||||
* disallow identical titles.
|
||||
* [valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md) - ensure expect is called correctly.
|
||||
|
||||
`;
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
run_spec(__dirname, { parser: "markdown" });
|
||||
run_spec(__dirname, { parser: "markdown", proseWrap: false });
|
||||
|
|
|
@ -208,6 +208,17 @@ exports[`show detailed usage with --help no-config (stdout) 1`] = `
|
|||
|
||||
exports[`show detailed usage with --help no-config (write) 1`] = `Array []`;
|
||||
|
||||
exports[`show detailed usage with --help no-prose-wrap (stderr) 1`] = `""`;
|
||||
|
||||
exports[`show detailed usage with --help no-prose-wrap (stdout) 1`] = `
|
||||
"--no-prose-wrap
|
||||
|
||||
Do not wrap prose. (markdown)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`show detailed usage with --help no-prose-wrap (write) 1`] = `Array []`;
|
||||
|
||||
exports[`show detailed usage with --help no-semi (stderr) 1`] = `""`;
|
||||
|
||||
exports[`show detailed usage with --help no-semi (stdout) 1`] = `
|
||||
|
@ -257,6 +268,19 @@ Default: 80
|
|||
|
||||
exports[`show detailed usage with --help print-width (write) 1`] = `Array []`;
|
||||
|
||||
exports[`show detailed usage with --help prose-wrap (stderr) 1`] = `""`;
|
||||
|
||||
exports[`show detailed usage with --help prose-wrap (stdout) 1`] = `
|
||||
"--prose-wrap
|
||||
|
||||
Wrap prose if it exceeds the print width. (markdown)
|
||||
|
||||
Default: true
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`show detailed usage with --help prose-wrap (write) 1`] = `Array []`;
|
||||
|
||||
exports[`show detailed usage with --help range-end (stderr) 1`] = `""`;
|
||||
|
||||
exports[`show detailed usage with --help range-end (stdout) 1`] = `
|
||||
|
@ -461,6 +485,7 @@ Format options:
|
|||
Defaults to babylon.
|
||||
--print-width <int> The line length where Prettier will try wrap.
|
||||
Defaults to 80.
|
||||
--no-prose-wrap Do not wrap prose. (markdown)
|
||||
--no-semi Do not print semicolons, except at the beginning of lines which may need them.
|
||||
--single-quote Use single quotes instead of double quotes.
|
||||
Defaults to false.
|
||||
|
@ -593,6 +618,7 @@ Format options:
|
|||
Defaults to babylon.
|
||||
--print-width <int> The line length where Prettier will try wrap.
|
||||
Defaults to 80.
|
||||
--no-prose-wrap Do not wrap prose. (markdown)
|
||||
--no-semi Do not print semicolons, except at the beginning of lines which may need them.
|
||||
--single-quote Use single quotes instead of double quotes.
|
||||
Defaults to false.
|
||||
|
|
Loading…
Reference in New Issue