From 51d386083eb1a24f57127267d6b486416b94b1c4 Mon Sep 17 00:00:00 2001 From: Christopher Quadflieg Date: Fri, 14 Feb 2020 09:59:04 +0100 Subject: [PATCH] Fix indentation for doctype --- .gitignore | 2 -- src/printer.ts | 2 +- test/pug-tests/blocks-in-if.formatted.pug | 19 +++++++++++++++++++ test/pug-tests/blocks-in-if.pug | 19 +++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 test/pug-tests/blocks-in-if.formatted.pug create mode 100644 test/pug-tests/blocks-in-if.pug diff --git a/.gitignore b/.gitignore index f30d3372..53b99c1a 100644 --- a/.gitignore +++ b/.gitignore @@ -75,8 +75,6 @@ test/pug-tests/attrs.unescaped.formatted.pug test/pug-tests/attrs.unescaped.pug test/pug-tests/block-code.formatted.pug test/pug-tests/block-code.pug -test/pug-tests/blocks-in-if.formatted.pug -test/pug-tests/blocks-in-if.pug test/pug-tests/comments.formatted.pug test/pug-tests/comments.pug test/pug-tests/comments.source.formatted.pug diff --git a/src/printer.ts b/src/printer.ts index 5edb12b7..2036cce5 100644 --- a/src/printer.ts +++ b/src/printer.ts @@ -690,7 +690,7 @@ export class PugPrinter { } private doctype(token: DoctypeToken): string { - let result = 'doctype'; + let result = `${this.computedIndent}doctype`; if (token.val) { result += ` ${token.val}`; } diff --git a/test/pug-tests/blocks-in-if.formatted.pug b/test/pug-tests/blocks-in-if.formatted.pug new file mode 100644 index 00000000..b0ccad76 --- /dev/null +++ b/test/pug-tests/blocks-in-if.formatted.pug @@ -0,0 +1,19 @@ +//- see https://github.com/pugjs/pug/issues/1589 + +- var ajax = true; + +- if( ajax ) + //- return only contents if ajax requests + block contents + p ajax contents + +- else + //- return all html + doctype html + html + head + meta(charset="utf8") + title sample + body + block contents + p all contetns diff --git a/test/pug-tests/blocks-in-if.pug b/test/pug-tests/blocks-in-if.pug new file mode 100644 index 00000000..e0c63611 --- /dev/null +++ b/test/pug-tests/blocks-in-if.pug @@ -0,0 +1,19 @@ +//- see https://github.com/pugjs/pug/issues/1589 + +-var ajax = true + +-if( ajax ) + //- return only contents if ajax requests + block contents + p ajax contents + +-else + //- return all html + doctype html + html + head + meta( charset='utf8' ) + title sample + body + block contents + p all contetns