diff --git a/packages/prettyprint/src/printNodes.js b/packages/prettyprint/src/printNodes.js index 335f411e..c12c2298 100644 --- a/packages/prettyprint/src/printNodes.js +++ b/packages/prettyprint/src/printNodes.js @@ -140,6 +140,29 @@ module.exports = function printNodes(nodes, printContext, inputWriter) { printers.printNode(child, printContext, childWriter); var childOutput = childWriter.getOutput(); + //Insert line break between tags + if ( + prevChild && + prevChild.type == "Text" && + /(?:\n|\r){2,}/.test(prevChild.argument.value) && + (/[a-zA-Z0-9]/.test(prevChild.argument.value) || + prevChild.previousSibling || + child.parentNode === "TemplateRoot") + ) { + writer.write(printContext.eol); + } + + //Insert line break before text node + if ( + child.type == "Text" && + /(?:\n|\r){2,}/.test(child.argument.value) && + /[a-zA-Z0-9]/.test(child.argument.value) && + prevChild && + prevChild.previousSibling + ) { + writer.write(printContext.eol); + } + if (childOutput.length) { if ( printContext.isHtmlSyntax && diff --git a/packages/prettyprint/test/autotest/js-block/expected.marko b/packages/prettyprint/test/autotest/js-block/expected.marko index 9fbadf20..f40b81e0 100644 --- a/packages/prettyprint/test/autotest/js-block/expected.marko +++ b/packages/prettyprint/test/autotest/js-block/expected.marko @@ -2,10 +2,12 @@ $ { var name = "Frank"; console.log(`Hello ${name}!`); } +
~~~~~~~ $ { var name = "Frank"; console.log(`Hello ${name}!`); } -div + +div \ No newline at end of file diff --git a/packages/prettyprint/test/autotest/js-line/expected.marko b/packages/prettyprint/test/autotest/js-line/expected.marko index 25ebc409..50577828 100644 --- a/packages/prettyprint/test/autotest/js-line/expected.marko +++ b/packages/prettyprint/test/autotest/js-line/expected.marko @@ -1,5 +1,7 @@ $ console.log("Hello World!"); +
~~~~~~~ $ console.log("Hello World!"); -div + +div \ No newline at end of file diff --git a/packages/prettyprint/test/autotest/preserve-el-whitespace/expected.marko b/packages/prettyprint/test/autotest/preserve-el-whitespace/expected.marko new file mode 100644 index 00000000..0ca509f1 --- /dev/null +++ b/packages/prettyprint/test/autotest/preserve-el-whitespace/expected.marko @@ -0,0 +1,40 @@ + + + + + + + + + + + + +-- Hello + + + + + World + + + +~~~~~~~ +a + +b + +c + d + e + + f + +-- Hello + +g + +h + -- World + + j \ No newline at end of file diff --git a/packages/prettyprint/test/autotest/preserve-el-whitespace/template.marko b/packages/prettyprint/test/autotest/preserve-el-whitespace/template.marko new file mode 100644 index 00000000..cd4b2eb5 --- /dev/null +++ b/packages/prettyprint/test/autotest/preserve-el-whitespace/template.marko @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + +-- Hello + + + + + + World + + + \ No newline at end of file diff --git a/packages/prettyprint/test/autotest/special-syntax-tags/expected.marko b/packages/prettyprint/test/autotest/special-syntax-tags/expected.marko index 7002c01c..6215ba20 100644 --- a/packages/prettyprint/test/autotest/special-syntax-tags/expected.marko +++ b/packages/prettyprint/test/autotest/special-syntax-tags/expected.marko @@ -3,6 +3,7 @@ .ccccccc() .ddddddd() .eeeeeee())>${aaaaaaaaaaa} + ${i} + ${aaaaaaaaaaa} @@ -23,6 +25,7 @@ for(aaaaaaaaaaa in aaaaaaaaaa .ccccccc() .ddddddd() .eeeeeee()) -- ${aaaaaaaaaaa} + for( var i = 1; i === @@ -33,6 +36,7 @@ for( .eeeeeee(); i++ ) -- ${i} + // not currently formattable for(aaaaaaaaaaa in aaaaaaaaaa.bbbbbbbbb().ccccccc().ddddddd().eeeeeee() | status-var=loop) -- ${aaaaaaaaaaa} \ No newline at end of file