3

html-tidy insists on minifying my style block into a single line. So this:

<style>
p { background-color: red; } 
#first {border: 2px solid blue} 
</style>

gets tidied into this:

<style>p { background-color: red; } #first {border: 2px solid blue}</style>

I want to keep my <style> block readable, so I'd take almost any variation as long as it treats <style> as a block level element, but I don't see any way to force that. The closest option I can see is new-blocklevel-tags, which doesn't have any impact and doesn't make sense as an option anyway.

How do I stop html-tidy from minifying CSS blocks inside of style tags?

Amanda
  • 12,099
  • 17
  • 63
  • 91
  • It's standard minification of styles...looks normal to me. – Paulie_D Jan 05 '16 at 23:53
  • 2
    Okay, but I want readable styles. I don't want them minified. – Amanda Jan 05 '16 at 23:57
  • Hmm...I've not used this but what I think you are looking for is the `indent-attributes` setting. Look in the Documentation for "How Do I Control the Output Layout?" http://www.html-tidy.org/documentation/ – Paulie_D Jan 05 '16 at 23:59
  • `indent-attributes` isn't it -- that puts attributes on their own line, but the inner text of a style block isn't attributes. – Amanda Jan 06 '16 at 00:58

1 Answers1

4

What you call minifying is actually removal of indenting. Minifying would mean the complete removal of all spaces, tabs and line breaks from your code, outputting it into one line, eventually compressing all your CSS in one file and all JavaScript in another.

Tidy is not capable of preserving the original indenting of the markup from the input it receives. That’s because Tidy starts by building a clean parse tree from the input, and that parse tree doesn’t contain any information about the original indenting. Tidy then pretty-prints the parse tree using the current config settings. Trying to preserve the original indenting from the input would interact badly with the repair operations needed to build a clean parse tree, and would considerably complicate the code.

Complete documentation here.

If you want to keep your indenting, stop using Tidy.

Response to proposed change by Amanda: I do not agree "if you want A, don't do B" is a hostile phrase construction and "If you want A, consider not doing B" should be used instead. For me, the second construct has more hostility, since it is a common structure for ironic comments. I don't want that. When I advise my very own kid, with the best intentions, not to put his hand on the stove if he doesn't want to get burns, I don't say "consider not putting your hand on the stove". I say: "If you don't want to get burns, don't put your hand on the stove." [Informative. Friendly. Not hostile.]

tao
  • 82,996
  • 16
  • 114
  • 150