feat(markdown): preserve `break` style (#3325)
parent
8524ed5b6f
commit
c1623d88e6
|
@ -398,7 +398,12 @@ function printDocToString(doc, options) {
|
||||||
out.pop();
|
out.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out.length) {
|
if (
|
||||||
|
out.length &&
|
||||||
|
(options.parser !== "markdown" ||
|
||||||
|
// preserve markdown's `break` node (two trailing spaces)
|
||||||
|
!/\S {2}$/.test(out[out.length - 1]))
|
||||||
|
) {
|
||||||
out[out.length - 1] = out[out.length - 1].replace(
|
out[out.length - 1] = out[out.length - 1].replace(
|
||||||
/[^\S\n]*$/,
|
/[^\S\n]*$/,
|
||||||
""
|
""
|
||||||
|
|
|
@ -315,7 +315,12 @@ function genericPrint(path, options, print) {
|
||||||
case "tableCell":
|
case "tableCell":
|
||||||
return printChildren(path, options, print);
|
return printChildren(path, options, print);
|
||||||
case "break":
|
case "break":
|
||||||
return concat(["\\", hardline]);
|
return concat([
|
||||||
|
/\s/.test(options.originalText[node.position.start.offset])
|
||||||
|
? " "
|
||||||
|
: "\\",
|
||||||
|
hardline
|
||||||
|
]);
|
||||||
case "tableRow": // handled in "table"
|
case "tableRow": // handled in "table"
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown markdown type ${JSON.stringify(node.type)}`);
|
throw new Error(`Unknown markdown type ${JSON.stringify(node.type)}`);
|
||||||
|
|
|
@ -3,7 +3,13 @@
|
||||||
exports[`simple.md 1`] = `
|
exports[`simple.md 1`] = `
|
||||||
123
|
123
|
||||||
456
|
456
|
||||||
|
|
||||||
|
123\\
|
||||||
|
456
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
123
|
||||||
|
456
|
||||||
|
|
||||||
123\\
|
123\\
|
||||||
456
|
456
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
123
|
123
|
||||||
456
|
456
|
||||||
|
|
||||||
|
123\
|
||||||
|
456
|
||||||
|
|
|
@ -2120,7 +2120,7 @@ exports[`example-186.md 1`] = `
|
||||||
aaa
|
aaa
|
||||||
bbb
|
bbb
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
aaa\\
|
aaa
|
||||||
bbb
|
bbb
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
@ -5772,7 +5772,7 @@ exports[`example-597.md 1`] = `
|
||||||
foo
|
foo
|
||||||
baz
|
baz
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
foo\\
|
foo
|
||||||
baz
|
baz
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
@ -5790,7 +5790,7 @@ exports[`example-599.md 1`] = `
|
||||||
foo
|
foo
|
||||||
baz
|
baz
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
foo\\
|
foo
|
||||||
baz
|
baz
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
@ -5799,7 +5799,7 @@ exports[`example-600.md 1`] = `
|
||||||
foo
|
foo
|
||||||
bar
|
bar
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
foo\\
|
foo
|
||||||
bar
|
bar
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
@ -5817,7 +5817,7 @@ exports[`example-602.md 1`] = `
|
||||||
*foo
|
*foo
|
||||||
bar*
|
bar*
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
_foo\\
|
_foo
|
||||||
bar_
|
bar_
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
Loading…
Reference in New Issue