Skip to content

Trim line breaks #19

Open
Open

Description

@andreyvolokitin

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'
]

Activity

  1. Scrum commented on Apr 9, 2018

    @Scrum
    Member

    there should be no ambiguity in parsing

  2. andreyvolokitin commented on Apr 9, 2018

    @andreyvolokitin
    Author

    What do you mean?

  3. andreyvolokitin commented on Apr 9, 2018

    @andreyvolokitin
    Author

    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>
    
  4. Scrum commented on Apr 9, 2018

    @Scrum
    Member

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

  5. changed the title [-]Trim line breaks[/-] [+]Trim whitespace[/+] on May 1, 2018
  6. changed the title [-]Trim whitespace[/-] [+]Trim line breaks[/+] on May 1, 2018
  7. added a commit that references this issue on May 1, 2018
  8. andreyvolokitin commented on May 1, 2018

    @andreyvolokitin
    Author
  9. stevenvachon commented on May 1, 2018

    @stevenvachon

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

  10. andreyvolokitin commented on May 1, 2018

    @andreyvolokitin
    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

  11. Scrum commented on Oct 10, 2019

    @Scrum
    Member

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

  12. andreyvolokitin commented on Oct 10, 2019

    @andreyvolokitin
    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)

  13. reopened this on Oct 10, 2019
  14. added this to the 1.3.2 milestone on Oct 10, 2019
  15. Scrum commented on Oct 10, 2019

    @Scrum
    Member

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

  16. andreyvolokitin commented on Oct 10, 2019

    @andreyvolokitin
    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)

  17. removed this from the 1.3.2 milestone on Jan 13, 2020
  18. adrian5 commented on Jul 11, 2023

    @adrian5

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions