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

This commit is contained in:
Ika authored and Lucas Azzola committed 2017-12-03 15:02:13 +11:00
1 parent 8524ed5b6f
commit c1623d88e6
5 files changed
+27 -8

No files matched your search

+6 -1
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]*$/,
""
+6 -1
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)}`);