How to "prove" I have closing tags?

1,335 views
Skip to first unread message

John Johnson

unread,
Aug 8, 2012, 8:51:26 PM8/8/12
to textwr...@googlegroups.com
I'm having a hard time matching all of my opening and closing tags,
especially <div> tags because there can be so much other markup in
between...

I don't see any TW tools that help this; maybe there are techniques?
I can find the opening tags, but I don't always know with certainty
whether I've found the close tag or not.

thanks for any clues!

wcat

Christopher Bort

unread,
Aug 8, 2012, 9:56:18 PM8/8/12
to textwr...@googlegroups.com
Make sure that the 'gutter' is displayed (View -> Text Display
-> Show|Hide Gutter), then use the fold indicators and the
folding commands in the View menu. Search for 'fold' in the User
Manual for details.
--
Christopher Bort
<top...@thehundredacre.net>

Steve

unread,
Aug 8, 2012, 10:45:17 PM8/8/12
to textwr...@googlegroups.com
While this may not be a perfect solution, here's one go at it:

(?s)<(\w+)>(?:(?!</\1>|<\w+>).)+<(\w+)>((?!</\2>|<\w+>).)+(?!</\2>)(?=<\w+>)

Use this in a grep-enabled search pattern. This example:

<dict>
<key>ThisWorks</key>
<string>Exactly like it should</string>
</dict>
<dict>
<key>ThisDoesNot
<string>Because of a closing "key" tag</string>
</dict>
<dict>
<key>ThisAlsoWorks</key>
<string>As expected</string>
<dict>
<key>ThisWorks</key>
<string>This does too
</dict>
</dict>

has a well-formed first <dict>...</dict> group, and a broken <dict>...</dict> group.  It will skip entirely over the first <dict> group and stop at the second.

It does have flaws, though. The second nested group will work if the </key> is missing, but apparently, not if the </string> is missing. So you may have to find another solution for that.

The easiest way IS as Chris mentioned: Use the gutter and use the fold indicators to let you know whether it is well-formed or not.

Thomas Humiston

unread,
Aug 8, 2012, 11:17:50 PM8/8/12
to textwr...@googlegroups.com
I've developed the habit of adding comments as labels on the closing tags of all but the smallest DIVs. A miniature example:

<div class=foo>
<p>Lorem ipsum dolor
sit amet and stick that in
your pipe and smoke it</p>
<!-- end foo --></div>

I place this identifier ahead of the tag so that it hides when the code is folded. (This also works when I view the code in Safari's Web Inspector tool, which I sometimes use for troubleshooting.)

If a large document got badly bunged and had no labels, I suppose I might save it over to my XP machine and open it with Notepad++. NPP's interface is clunky but it can highlight matching HTML tags.

- TH

Christopher Bort

unread,
Aug 9, 2012, 12:17:29 AM8/9/12
to textwr...@googlegroups.com
On 8/8/12 at 8:17 PM, t...@jumpingrock.net (Thomas Humiston) wrote:

>I've developed the habit of adding comments as labels on the closing
>tags of all but the smallest DIVs. A miniature example:
>
><div class=foo>
><p>Lorem ipsum dolor
>sit amet and stick that in
>your pipe and smoke it</p>
><!-- end foo --></div>
>
>I place this identifier ahead of the tag so that it hides when
>the code is folded. (This also works when I view the code in
>Safari's Web Inspector tool, which I sometimes use for troubleshooting.)

I do that too, and it saves a lot of hair that would otherwise
be pulled out looking for unbalanced tags. 8^)

>If a large document got badly bunged and had no labels, I
>suppose I might save it over to my XP machine and open it with
>Notepad++. NPP's interface is clunky but it can highlight
>matching HTML tags.

Ick. If you can justify shelling out for TextWrangler's big
brother BBEdit, it has a 'Balance Tags' command that works
simliarly to the Balance command for parens and brackets.

>On Aug 8, 2012, at 8:51 PM, John Johnson wrote:
>
>>I'm having a hard time matching all of my opening and closing tags,
>>especially <div> tags because there can be so much other markup in
>>between...
>>
>>I don't see any TW tools that help this; maybe there are techniques?
>>I can find the opening tags, but I don't always know with certainty
>>whether I've found the close tag or not.
>>
>>thanks for any clues!
>>
>>wcat
--
Christopher Bort
<top...@thehundredacre.net>

Thomas Fischer

unread,
Aug 9, 2012, 3:50:21 AM8/9/12
to textwr...@googlegroups.com
Hi John,

I use the Unix command xmllint as a Text Filter, this works well for XML, also for parts of HTML.
Best if it proves that everything is OK, somewhat more tedious if it gives errors, e.g. because line count refers to the lines of the selection.
Copy these lines to a file and save it as xmllint.sh (or anything you want) to the TextWrangler's Text Filters folder at
~/Library/Application Support/TextWrangler/Text Filters/
then call it on the whole text or the selection:
-----------------
#!/bin/sh

XMLLINT_INDENT=$'\t' xmllint --format --encode utf-8 -

# XMLLINT_INDENT=$'\t' : set indentation to "tab"
# - at end gives STDIN
-----------------

Hope this is useful.
Best
Thomas
> --
> You received this message because you are subscribed to the
> "TextWrangler Talk" discussion group on Google Groups.
> To post to this group, send email to textwr...@googlegroups.com
> To unsubscribe from this group, send email to
> textwrangler...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/textwrangler?hl=en
> If you have a feature request or would like to report a problem,
> please email "sup...@barebones.com" rather than posting to the group.

John Johnson

unread,
Aug 8, 2012, 10:44:21 PM8/8/12
to textwr...@googlegroups.com
OK..I do see those...and maybe sometimes, it's a matter of folding all
the stuff in between to visually be able to see a connection between a
fold triangle and that sideways "L" thing that points up to it?

cat

John Johnson

unread,
Aug 8, 2012, 10:47:11 PM8/8/12
to textwr...@googlegroups.com
will do...(use the fold indicators)

the algebraic-looking string you typed below..how does one use that?

Michael Bierman

unread,
Aug 9, 2012, 12:37:11 AM8/9/12
to textwr...@googlegroups.com
Tag matching is a very nice feature.

--
Michael Bierman
408-692-5229 | @mbierm | http://linkedin.com/in/michaelbierman |
http://thebiermans.net
Sent from my mobile device with clumsy fingers

John Johnson

unread,
Aug 9, 2012, 10:59:38 AM8/9/12
to textwr...@googlegroups.com
thank you all for the great and helpful responses...I think I'll
incorporate commenting more, too!

John
Reply all
Reply to author
Forward
0 new messages