posthtml-include
posthtml-include copied to clipboard
Trim line breaks
It makes sense to remove line breaks from start and end of the included tree (especially considering that line break at the end is often inserted automatically by code editor)
[
'\n',
{tag: 'a'},
'\n'
]
or
[
'\n some text \n'
]
there should be no ambiguity in parsing
What do you mean?
Currently, I'm trying to do this in posthtml-extend and it looks pretty easy. I will make a PR there and then we'll see. The main point is that the module/include should not dictate vertical whitespace outside its own boundaries, because it is simply a module, and such formatting should be done within the main file which includes this module, i.e. this code:
<h2>Head</h2>
<include src="module.html"></include>
<h2>Head</h2>
should end up like this:
<h2>Head</h2>
module contents
<h2>Head</h2>
and not like this:
<h2>Head</h2>
module contents
<h2>Head</h2>
if it's part of posthtml-include then you are right
Check this out: https://github.com/posthtml/posthtml-extend/pull/14
There's a potential smell to this request. See normalize-html-whitespace.
There is mainly vertical whitespace / linebreaks problem (specifically with posthtml-include, which is different to posthtml-extend). The leading/trailing line breaks for the first/last text node should be removed somehow (and not replaced by a single space as normalize-html-whitespace suggests). Because the contents of include.html as such:
...shouldn't dictate its own vertical formatting. Also trailing line break is often added automatically/unintentionally
I think it’s suitable for this case posthtml-beautify
Then it might be impossible to keep the original project indentation intact (see https://github.com/posthtml/posthtml-beautify/issues/220 and https://github.com/posthtml/posthtml-beautify/pull/222) if we will try to fix this later with another tool like posthtml-beautify, because we will not know if these line breaks should be removed (if they are from posthtml-include) or not (if they are set by developer)
@andreyvolokitin I’ll try to figure it out, so far I don’t really understand how it should work
I think I've done something similar for posthtml-extend: https://github.com/posthtml/posthtml-extend/pull/14/files, though I'm not sure if it can be applied to posthtml-include. Generally I think that it should remove line breaks from the start and the end of the tree (so the leading line break for the first node, and the trailing line break for the last node, or both if the tree consists of a single node)
Any chance to get this fixed in posthtml-include? I agree with Andrey that the included snippet shouldn't contain extra newlines beyond its bounds. Text editors do tend to add a single trailing newline to files.