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(); 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]*$/,
"" ""

View File

@ -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)}`);

View File

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

View File

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

View File

@ -903,7 +903,7 @@ exports[`example-85.md 1`] = `
exports[`example-86.md 1`] = ` exports[`example-86.md 1`] = `
foo foo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo foo
`; `;
@ -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_
`; `;