How do I get HTML Tidy to not put newline before closing tags?
Asked Answered
N

3

19

HTML Tidy has this infuriating habit of putting a newline before the closing tag. For example:

<p>Some text</p>

becomes

<p>Some text
</p>

How do I tell Tidy to keep the closing tag on the same line as the end of the content?

Btw, I am running Tidy through Notepad++, if that makes any difference.

Norty answered 22/3, 2010 at 11:9 Comment(0)
I
16

Make sure vertical-space is set to no. After much frustration I learned the only thing that switch does is screw up your already somewhat-nicely formatted html by adding newlines where you don't want them.

This is what I use for minimally-invasive tidying (no adding doctypes/head tags, etc.):

tidy -mqi --doctype omit --show-body-only true --show-warnings no --vertical-space no --wrap 0

Internalcombustion answered 6/10, 2011 at 22:59 Comment(1)
Upvoted, but feel I should add a warning to readers: the -m option causes tidy to modify files in place (i.e. to overwrite them). Omit it unless you have a backup, or are otherwise happy for your existing file(s) to be clobbered.Defeasible
E
1

hmm I don't see it in windows.

I am using Tidy with ruby

   @tidy.options.output_xhtml = true
   @tidy.options.show_body_only = true
   @tidy.clean('<p>Some text</p>')

I also ran the tidy script in unbuntu (tidy -m test.htm) but did not see that problem. You can control the spacing using the options at http://tidy.sourceforge.net/docs/quickref.html#PrettyPrintHeader

Eulaheulalee answered 19/4, 2010 at 17:56 Comment(2)
I've looked at those options before and none of those seem to do the needful. Btw, I am running TIDY through Notepad++, if that makes any difference.Norty
don't know how to do it with NotePad++ but 'wrap=160' option might help. But the issue that you are seeing might be related to notePad++Eulaheulalee
K
-9

In php you can use:

$buffer = preg_replace('/\n<\//smUi','</',$buffer);
Kithara answered 16/8, 2010 at 22:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.