posthtml / posthtml-extend

Template extending (Jade-like)
MIT License
46 stars 9 forks source link

feat: trim whitespace #14

Open andreyvolokitin opened 6 years ago

andreyvolokitin commented 6 years ago

Remove whitespace at the start/end of the first/last text node. Related: https://github.com/posthtml/posthtml-include/issues/19.

I realized that for posthtml-extend it makes sense to remove not only line breaks but all whitespace instead. Because it can interfere with formatting, when actual html is inside multiple nested control tags, i.e. <block> inside <extends>:

<extends src="foo.html">
    <block name="bar">
        << Parasitic whitespace to the left (as well as a line break above and below)
    </block>
</extends>

If there is whitespace in the middle of a string, then it remains untouched and definitely should be handled by html beautifier later:

<extends src="foo.html">
    <block name="bar">
        << Parasitic whitespace to the left (as well as a line break  above and below).
        << Parasitic whitespace to the left again, this time it gets inserted to the actual output
    </block>
</extends>