Loading ...
Sorry, an error occurred while loading the content.

4952Re: [NH] match html tag

Expand Messages
  • Don - htmlfixit.com
    Jan 10, 2005
    • 0 Attachment
      Here is my try. It appears to be finding the proper tags in my testing.
      Unfortunately it isn't displaying right when I am done. In my
      example, it winds up with the text off to the left and not visible. If
      I copy and paste the selected, then I see I got the right stuff.

      Once I get it working I will turn it around to find the matching start tag.

      ;*** Effort by Don Passenger
      ;*** don@...
      ;*** discuss things live in chat at http://htmlfixit.com
      ;*** based on work by Larry and Jody and maybe Wayne
      ;*** will check for a matching html tag

      ^!Continue [C]Is cursor in the tag you want to find a match for and then
      start clip

      ;### initialize everything
      ;assume we have our cursor in a tag
      ;look backwards to find the starting <
      ^!Find "<" TIBS
      ;exit if find fails
      ^!IfError EXIT
      ;figure out where cursor is
      ^!Set %row%="^$GetRow$"
      ^!Set %column%="^$GetCol$"

      ^!SetScreenUpdate Off
      ^!SetWordWrap Off

      ;### %TAG% will be empty if cursor is not inside a tag.
      ^!Set %TAG%="^$GetHtmlTag(TRUE)$"
      ^!IfTrue ^$IsEmpty(^%TAG%)$ NotTag
      ^!If "/>" = "^$StrCopyRight("^$GetSelection$";2)$" SelfClosing

      ;### So we found a tag. What tag is it?
      ^!Set %TAGNAME%="^$GetHtmlTagName("^%TAG%";UPPERCASE)$"
      ^!Continue ^%TAGNAME%
      ^!Jump Select_End
      ^!Set %TAGCOUNT%=1
      ^!Info [C]^%TAGCOUNT%
      ^!If "/" = "^$StrCopyLeft("^%TAGNAME%";1)$" FindNextTagBackwards ELSE

      ^!Find "<" TIS
      ^!IfError UnMatched
      ^!Set %TAGTEMP%="^$GetHtmlTag(TRUE)$"
      ^!IfTrue ^$IsEmpty(^%TAGTEMP%)$ NextTag
      ^!Set %TAGTEMPNAME%="^$GetHtmlTagName("^%TAGTEMP%";UPPERCASE)$"
      ^!If "/" = "^$StrCopyLeft("^%TAGTEMPNAME%";1)$" EndTag ELSE BeginTag

      ^!Info [C]End Tag
      ^!If "^$StrDeleteLeft("^%TAGTEMPNAME%";1)$" <> "^%TAGNAME%" Skip_2
      ^!Dec %TAGCOUNT%
      ^!If "^%TAGCOUNT%" = "0" Match
      ^!Goto NextTag

      ^!Info [C]Beginning Tag
      ^!If "^%TAGTEMPNAME%" <> "^%TAGNAME%" Skip_2
      ^!Inc %TAGCOUNT%
      ^!If "^%TAGCOUNT%" = "0" Match
      ^!Goto NextTag

      ^!Info [C]^%TAGCOUNT% -- ^%TAGTEMPNAME%

      ^!Jump Select_End
      ^!Goto FindNextTagForwards

      ^!Info [C]Backwards not working yet ... will search towards the front of
      the document
      ^!Goto Finish

      ^!SetScreenUpdate On
      ^!SetWordWrap On
      ^!Info [C]Bingo, we have a match!.
      ^!Jump SELECT_END
      ^!SelectTo ^%row%:^%column%
      ^!Goto Finish

      ^!SetCursor ^%row%:^%column%
      ^!Info [C]This appears to be an unmatched Tag. We made it to the end of
      your document without finding a match.
      ^!Goto Finish

      ^!SetCursor ^%row%:^%column%
      ^!Info [C]This appears to not be an html tag. Remember have your cursor
      inside the tag when starting this clip.
      ^!Goto Finish

      ^!SetCursor ^%row%:^%column%
      ^!Info [C]Your tag is self closing - quit messing with me! Self closing
      tags end in /> like <br />

      ;### clean up and go home
      ^!SetScreenUpdate On
      ^!SetWordWrap On
      ;line 110 if you have all lines unrapped (including blank lines)
    • Show all 10 messages in this topic