Hi,
this macro should work. I use a Perl script as an event based parser. This approach should be quite robust against (X|H)TML syntax. The disadvantage is speed. To increase the speed even for very large documents I implemented a two-step parser. The first step assumes that the sought open tag is closed to the caret (meaning 6000 bytes). If nothing is found the second step will parse the entire document that could takes a bit (more than 10,000 lines). With this macro I also got rid of the Perl regexp engine crash on large documents. I tried it out. I took an HTML file with 45,000 lines and it worked fine for tags which are closed to the caret. If the tags are not closed to the caret it takes a while but one can stop the macro by pressing APPLE+.
If the macro shouldn't find anything or the start tag name differs from the end tag name - which is the case if one works with incomplete (X|H)TML - the macro will play an alert sound.
Of course, that macro cannot parse any HTML exception. E.g. one can write: <tr><td><p>foo</td></tr> . The <p> tag will be closed by </td>.
An other issue is the <script> tag. Up to now the macro allows to select <script>..</script> but e.g. in JavaScript one can write: document.write("<SCR" + "IPT='2' SRC='/footers/sites/"+ site_name +".js' TYPE='text/javascript'></SCR" + "IPT>"); "<SCR" won't be ignored!
QUESTION: Should the macro ignore any <script>..</script> tags?
I rebound the macro to SHIFT+OPT+APPLE+B because I find it sometimes quite useful to have to chance to invoke 'Enclosing Brackets' in (X|H) TML but this is up to the user.
Please try it out and give a feedback ;)
Cheers,
--Hans