You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
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:
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
Reacted by Steven Vachon, Ivan Demidov, Matronator and adrian5
Then it might be impossible to keep the original project indentation intact (see posthtml/posthtml-beautify#220 and posthtml/posthtml-beautify#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)
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.
Activity
Scrum commentedon Apr 9, 2018
there should be no ambiguity in parsing
andreyvolokitin commentedon Apr 9, 2018
What do you mean?
andreyvolokitin commentedon Apr 9, 2018
Currently, I'm trying to do this in
posthtml-extendand 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:should end up like this:
and not like this:
Scrum commentedon Apr 9, 2018
if it's part of
posthtml-includethen you are right[-]Trim line breaks[/-][+]Trim whitespace[/+][-]Trim whitespace[/-][+]Trim line breaks[/+]feat: trim whitespace
andreyvolokitin commentedon May 1, 2018
Check this out: posthtml/posthtml-extend#14
stevenvachon commentedon May 1, 2018
There's a potential smell to this request. See normalize-html-whitespace.
andreyvolokitin commentedon May 1, 2018
There is mainly vertical whitespace / linebreaks problem (specifically with

posthtml-include, which is different toposthtml-extend). The leading/trailing line breaks for the first/last text node should be removed somehow (and not replaced by a single space asnormalize-html-whitespacesuggests). Because the contents ofinclude.htmlas such:...shouldn't dictate its own vertical formatting. Also trailing line break is often added automatically/unintentionally
Scrum commentedon Oct 10, 2019
I think it’s suitable for this case posthtml-beautify
andreyvolokitin commentedon Oct 10, 2019
Then it might be impossible to keep the original project indentation intact (see posthtml/posthtml-beautify#220 and posthtml/posthtml-beautify#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 fromposthtml-include) or not (if they are set by developer)Scrum commentedon Oct 10, 2019
@andreyvolokitin I’ll try to figure it out, so far I don’t really understand how it should work
andreyvolokitin commentedon Oct 10, 2019
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 toposthtml-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)adrian5 commentedon Jul 11, 2023
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.