user606521
user606521

Reputation: 15454

How to force tidy not to change HTML?

I am using following command to format HTML:

tidy -xml --merge-divs no --wrap 0 --force-output yes --indent auto --indent-spaces 2 --quiet yes

It works fine except it automatically closes tags like this:

<br> -> <br></br>
<br><br> -> <br><br></br></br>
<div><input><span></span></div> -> <div><input><span></span></input></div>

As you can see it tries to close every tag - how I can fore it not to do that and leave tags untouched or at least close them "inline" like this:

<br><br> -> <br/><br/>

The closest I want is using this command:

tidy -asxhtml --hide-endtags yes --doctype omit --merge-divs no --wrap 0 --force-output yes --indent auto --indent-spaces 2 --quiet yes

However from this HTML:

<div><input type="text"><span>abc</span></div><br><br>

It generates this:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta name="generator" content="HTML Tidy for Mac OS X (vers 31 October 2006 - Apple Inc. build 15.12), see www.w3.org" />

  <title></title>
</head>

<body>
  <div>
    <input type="text" /><span>abc</span>
  </div><br />
  <br />
</body>
</html>
  1. I dont want html, meta, body etc tags to be autmatically added
  2. I dont want br and input tags to be auto closed
  3. why span is in the same line as input?
  4. Why br is in the same line as </div>?

I found option show-body-only which does not output html, body, etc tags. However still output is like this:

<div>
  <input type="text" /><span>abc</span>
</div><br />
<br />
  1. I dont want input/br tags to be auto closed
  2. I dont want span to be in the same line as input
  3. I dont want br to be on the same line as div close tag

Upvotes: 1

Views: 1048

Answers (1)

Ulrich Schwarz
Ulrich Schwarz

Reputation: 7727

You're passing the wrong flags. Quoting man tidy:

-xml   specify the input is well formed XML (input-xml: yes)

but what you probably want is

-asxml, -asxhtml
         convert HTML to well formed XHTML (output-xhtml: yes)

Upvotes: 2

Related Questions