0

I have some HTML documents that I need to batch fix. The main problems in the file are:

  • Out of order tags (<p><i>like this</p></i>)
  • Unclosed tags (<p>like this)

I know the output won't be perfect, but I need to repair these simple problems quickly for further processing.

Is there a tool for this? I want a command-line tool that runs on Mac OS X or Linux. If there's nothing available, I'll end up writing my own, but I'd prefer something that's already built for the task, if it exists.

To clarify: This isn't a software recommendation question - I'm pretty sure there's no single piece of software that will do this, I'm looking more for bits and pieces to put together, like sed/awk/Python/etc. that can accomplish it. The two primary problems are the out of order and unclosed tags mentioned above. If I can solve those, the remaining problems are much easier to solve (encoding, etc.)

  • Sorry, software recommendations are off topic. We could help you script something but would need to know what tags you're after. – terdon Nov 25 '13 at 14:01
  • I'm not looking for software recommendations exactly, but more recommendations on tools or tricks for accomplishing it without writing a completely custom program. For example, a couple sed commands or an awk script might be appropriate, but my regex knowledge is fairly limited. Also, sed may not work since these can span multiple lines, so awk or even just a custom Python script may be the best solution. I'm fairly open to suggestions. – Justin Mrkva Nov 25 '13 at 14:28
  • The thing is, this is not trivial and cannot be done by regular expressions. It might be done with a regex for a small list of specific tags but what about tags like <input> which don't close? Or the difference between <p> and <p class="foo" style="color:blue">? Or <p> and < p>? – terdon Nov 25 '13 at 14:41
0

HTML Tidy:

HTML Tidy is a tool for checking and cleaning up HTML source files. It is especially useful for finding and correcting errors in deeply nested HTML, or for making grotesque code legible once more.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.