phug-php / phug

Phug - The Pug Template Engine for PHP
https://phug.selfbuild.fr
MIT License
63 stars 3 forks source link

All whitespaces get removed #46

Closed OnkelTem closed 5 years ago

OnkelTem commented 5 years ago

I have the next template:

ul
  each i in range(1, 7)
    td asd

And the output is:

<ul><td>asd</td><td>asd</td><td>asd</td><td>asd</td><td>asd</td><td>asd</td><td>asd</td></ul>

I cannot find the reason. Any ideas?

kylekatarnls commented 5 years ago

Indentation of Pug determines the nesting of elements, not the HTML indentation. Then Pug generates also PHP codes (mixins, includes, etc.) so you won't have consistent indentation across both PHP and HTML output. Minified HTML is faster to download so you should not need to add whitespaces in output.

You still can check the pretty option: https://phug-lang.com/#pretty-boolean-string

But I would rather recommend to check HTML formatting dedicated packages. But consider wisely if you really need to format your HTML output, It should be only rares cases, such as displaying a HTML code snippet in some <pre> element.

OnkelTem commented 5 years ago

I agree we don't need this pretty print for production. But my case is special -- I generate Anki decks and you see, its users get used to have access to card templates editing. So they won't be happy to see optimized HTML :)

kylekatarnls commented 5 years ago

OK so you may better use some third-library like: https://packagist.org/packages/mihaeu/html-formatter this way the final HTML is well indented no matter you use mixin, includes or any stuff.