feat(markdown): preserve `break` style (#3325)

master
Ika 2017-12-03 12:02:13 +08:00 committed by Lucas Azzola
parent 8524ed5b6f
commit c1623d88e6
5 changed files with 27 additions and 8 deletions

View File

@ -398,7 +398,12 @@ function printDocToString(doc, options) {
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(
/[^\S\n]*$/,
""

View File

@ -315,7 +315,12 @@ function genericPrint(path, options, print) {
case "tableCell":
return printChildren(path, options, print);
case "break":
return concat(["\\", hardline]);
return concat([
/\s/.test(options.originalText[node.position.start.offset])
? " "
: "\\",
hardline
]);
case "tableRow": // handled in "table"
default:
throw new Error(`Unknown markdown type ${JSON.stringify(node.type)}`);

View File

@ -3,7 +3,13 @@
exports[`simple.md 1`] = `
123
456
123\\
456
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123
456
123\\
456

View File

@ -1,2 +1,5 @@
123
456
123\
456

View File

@ -903,7 +903,7 @@ exports[`example-85.md 1`] = `
exports[`example-86.md 1`] = `
foo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo
foo
`;
@ -2120,7 +2120,7 @@ exports[`example-186.md 1`] = `
aaa
bbb
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aaa\\
aaa
bbb
`;
@ -5772,7 +5772,7 @@ exports[`example-597.md 1`] = `
foo
baz
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo\\
foo
baz
`;
@ -5790,7 +5790,7 @@ exports[`example-599.md 1`] = `
foo
baz
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo\\
foo
baz
`;
@ -5799,7 +5799,7 @@ exports[`example-600.md 1`] = `
foo
bar
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo\\
foo
bar
`;
@ -5817,7 +5817,7 @@ exports[`example-602.md 1`] = `
*foo
bar*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foo\\
_foo
bar_
`;