Quickies
HTML Tag Matcher

TagMatch v1.0.2007.06.05

Say, for example, that a large part of your job is to incorporate chunks of HTML generated by third-parties and blatting them into a larger page. It's easy enough to strip off the extra body and html tags they gave you. It's annoying, but you can find a way to get all of their javascript stuff linked into your page. But, their html has unbalanced table tags and div tags all over the place that are blowing holes in your nice page template.

This is a quick hack that checks to see that some of the killer tags are balanced.

By default, it checks for:

  • blockquote
  • center
  • div
  • dl
  • ol
  • table
  • tbody
  • td
  • thead
  • tr
  • ul

You can specify others on the command-line with -t tag. So, to check for balanced body tags, in addition to the default, for the files foo and bar, you would do:

  perl tagmatch.pl -t body foo bar

Here is the Perl source code.