threedaymonk / htmlbeautifier

A normaliser/beautifier for HTML that also understands embedded Ruby. Ideal for tidying up Rails templates.
MIT License
325 stars 59 forks source link

Allow optional comment start and end points #28

Closed olsonpm closed 7 years ago

olsonpm commented 9 years ago

This enables comments to be used as a means to remove whitespace between elements.

threedaymonk commented 9 years ago

I don't really understand why you'd want to do this, which makes me reticent to merge it. Can you explain the motivation and use cases?

olsonpm commented 9 years ago

So how do you remove whitespace between inline-block elements? Putting comments inbetween them is one method of doing so. E.g.

<style>
  ul > li {
    display: inline-block;
    width: 50%;
  }
</style>

<ul>
  <li>list item 1</li>
  <li>list item 2</li>
</ul>

// vs

<ul>
  <li>list item 1</li><!--
  --><li>list item 2</li>
</ul>

https://jsfiddle.net/sejjg16e/

So in the above scenario, how would you remove the inherent whitespace to allow the 50% width without wrapping?

threedaymonk commented 9 years ago

I can honestly say it's never come up! I suppose there are various solutions to that problem, but putting comments at the start and end of lines feels like a hack to me. However, adding specific indenting support for half a comment feels like even more of a hack, and I can't help feeling that it will cause other unforeseen problems.

olsonpm commented 9 years ago

Well according to various articles, and most plainly this one - there are many solutions. None of which are ideal as css hasn't addressed the problem, but it is a common problem so they are honest solutions. Using floats is a possible solution but in my mind floats should be reserved for filling variable horizontal space or for when taking an element out of flow is desired.

And I don't mean to argue as I'm very happy keeping a fork of this project for personal use. I also understand I'm not a maintainer and don't have to worry about future time spent.

As a side note, I was using js-beautify previously (which also formats html) until I had the need for erb syntax which they didn't support. Your library tackles the same problem in a much more succinct manner. It was fun to learn.