Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim line breaks #19

Open
andreyvolokitin opened this issue Apr 7, 2018 · 12 comments
Open

Trim line breaks #19

andreyvolokitin opened this issue Apr 7, 2018 · 12 comments

Comments

@andreyvolokitin
Copy link

andreyvolokitin commented Apr 7, 2018

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'
]
@Scrum
Copy link
Member

Scrum commented Apr 9, 2018

there should be no ambiguity in parsing

@andreyvolokitin
Copy link
Author

What do you mean?

@andreyvolokitin
Copy link
Author

andreyvolokitin commented Apr 9, 2018

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>

@Scrum
Copy link
Member

Scrum commented Apr 9, 2018

if it's part of posthtml-include then you are right

@andreyvolokitin andreyvolokitin changed the title Trim line breaks Trim whitespace May 1, 2018
@andreyvolokitin andreyvolokitin changed the title Trim whitespace Trim line breaks May 1, 2018
andreyvolokitin added a commit to andreyvolokitin/posthtml-extend that referenced this issue May 1, 2018
Remove whitespace at the start/end of the first/last text node. Details: posthtml/posthtml-include#19
@andreyvolokitin
Copy link
Author

Check this out: posthtml/posthtml-extend#14

@stevenvachon
Copy link

stevenvachon commented May 1, 2018

There's a potential smell to this request. See normalize-html-whitespace.

@andreyvolokitin
Copy link
Author

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:
Image of Yaktocat
...shouldn't dictate its own vertical formatting. Also trailing line break is often added automatically/unintentionally

@Scrum
Copy link
Member

Scrum commented Oct 10, 2019

I think it’s suitable for this case posthtml-beautify

@Scrum Scrum closed this as completed Oct 10, 2019
@andreyvolokitin
Copy link
Author

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)

@Scrum Scrum reopened this Oct 10, 2019
@Scrum Scrum added this to the 1.3.2 milestone Oct 10, 2019
@Scrum
Copy link
Member

Scrum commented Oct 10, 2019

@andreyvolokitin I’ll try to figure it out, so far I don’t really understand how it should work

@andreyvolokitin
Copy link
Author

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)

@Scrum Scrum removed this from the 1.3.2 milestone Jan 13, 2020
@adrian5
Copy link

adrian5 commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants