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

[feat]: Customize/turn off formatting rules #216

Closed
andreyvolokitin opened this issue Jan 16, 2018 · 12 comments
Closed

[feat]: Customize/turn off formatting rules #216

andreyvolokitin opened this issue Jan 16, 2018 · 12 comments
Milestone

Comments

@andreyvolokitin
Copy link

Is it possible currently? In the docs I see 3 rules available for customization. For now, I need to turn off vertical indentation (it honestly looks somewhat confusing, because it makes empty lines in unexpected places). All in all, I would prefer to just use horizontal indentation because that's what gets broken while using posthtml-include and such. Everything else I handle myself and would prefer to keep unchanged

@andreyvolokitin
Copy link
Author

Removed last getIndent(0), that removed all vertical indentation. So I'm afraid that currently, it is not possible to preserve original vertical indentation because it gets destroyed in the first place?

@Scrum
Copy link
Member

Scrum commented Jan 16, 2018

Yes, all initial formatting is deleted. A new one is created. Show me how you would like and I'll think about how best to do it.

related #217

@andreyvolokitin
Copy link
Author

My problem is that when using posthtml-include or posthtml-extend the HTML which gets outputted by these plugins is lacking proper horizontal formatting, like so:

<!doctype html>
<html class="no-js" lang="">
    <head>
        <meta charset="utf-8">
    </head>
    <body>
    <h2>Extend:</h2>

    <div class="posthtml-include-output">
  <div class="content">
    Read
  </div>
  <footer>
    footer
  </footer>
</div>
    </body>
</html>

so I want to just fix horizontal indentation of HTML outputted by these plugins.

I guess this is probably even worth a separate plugin like posthtml-fix-output as the difference with the goals of posthtml-beautify is huge... It would be possible though if every tiny rule of posthtml-beautify would be pluggable, so only desired rules/transformations could be turned on. There are already an array of transformations which can be tweaked, but transformations themselves seems like lacking granular control

@andreyvolokitin
Copy link
Author

Probably better use something like this after webpack build: https://github.com/beautify-web/js-beautify#css--html, it appears like a big task to adapt posthtml-beautify for my use case

@Scrum
Copy link
Member

Scrum commented Jan 17, 2018

beautify-web/js-beautify most likely it will also remove all your current indentation and create your own based on the options.

it appears like a big task to adapt posthtml-beautify for my use case

you will be easier to configure posthtml-cli - I will make a new pool requester in your repository posthtml-beautify-test where I will show that this is easy

@andreyvolokitin
Copy link
Author

Thanks, would appreciate it. js-beautify indeed reformats everything (which is somewhat undesirable), but it can be tuned, i.e. I can keep almost all original vertical indentation preserved there (https://github.com/beautify-web/js-beautify/blob/master/js/lib/beautify-html.js#L53). Though it yet cannot understand cases when collapsed whitespace between tags needs to stay preserved, instead it adds a new line between them, which is critical because it can break HTML layout which depends on presence or absence of whitespace

@Scrum Scrum added this to the 0.2.0 milestone Jan 21, 2018
@Scrum Scrum changed the title Customize/turn off formatting rules [feat]: Customize/turn off formatting rules Jan 21, 2018
Scrum added a commit that referenced this issue Jan 24, 2018
@Scrum
Copy link
Member

Scrum commented Jan 24, 2018

@andreyvolokitin Hi, So far I've added an option for management blankLines, also created a task to save the current structure #220.

And I also remember about the example that promised, now posthtml-cli he had difficulties and I solve them

@Scrum Scrum closed this as completed in 00ce993 Jan 25, 2018
@andreyvolokitin
Copy link
Author

Have I understood it correctly: blankLines option controls the addition of new newlines, but not removing existing newlines? To preserve existing newlines and overall structure there is #220, correct?

@Scrum
Copy link
Member

Scrum commented Jan 25, 2018

@andreyvolokitin remove all blankLines

input.html

<div>

<div>test</test>

</div>

output.html

<div>
  <div>test</test>
</div>

#220 to save the current structure with formatted indents.

@andreyvolokitin
Copy link
Author

OKay, so the process is this:

  • currently by designposthtml-beautify removing all blank lines
  • then some blank lines are added due to this feature: https://i.imgur.com/Sf4ZrSP.png
  • but you can disable this feature with blankLines: false, and in that case no such blank lines are added
  • the final result of this is the example you provided: all blank lines are removed, but none are added.

I think this is what you meant

@Scrum
Copy link
Member

Scrum commented Feb 21, 2018

@andreyvolokitin 🎉🎉🎉 try.

you will be easier to configure posthtml-cli - I will make a new pool requester in your repository posthtml-beautify-test where I will show that this is easy

andreyvolokitin/posthtml-beautify-test#2

@andreyvolokitin
Copy link
Author

Thanks! Will check it out

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

2 participants