diff --git a/src/printer.ts b/src/printer.ts index d13b3fe..2e8a1f4 100644 --- a/src/printer.ts +++ b/src/printer.ts @@ -228,6 +228,14 @@ const buildBlock = ( block: Block, mapped: (string | builders.Doc[] | builders.DocCommand)[] ): builders.Doc => { + // if the content is empty or whitespace only. + if (block.content.match(/^\s*$/)) { + return builders.fill([ + path.call(print, "nodes", block.start.id), + builders.softline, + path.call(print, "nodes", block.end.id), + ]); + } if (block.containsNewLines) { return builders.group([ path.call(print, "nodes", block.start.id), diff --git a/test/cases/statement_empty_block/expected.html b/test/cases/statement_empty_block/expected.html new file mode 100644 index 0000000..bdeb0de --- /dev/null +++ b/test/cases/statement_empty_block/expected.html @@ -0,0 +1,2 @@ +{% block title %} +{% endblock %} diff --git a/test/cases/statement_empty_block/input.html b/test/cases/statement_empty_block/input.html new file mode 100644 index 0000000..39d5168 --- /dev/null +++ b/test/cases/statement_empty_block/input.html @@ -0,0 +1,5 @@ +{% block title %} + + + +{% endblock %} \ No newline at end of file