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

Matching Tags Clip

Expand Messages
  • John Zeman <john041650@yahoo.com>
    Ok then here it is Christine and anyone else interested. To use this clip put your mouse cursor somewhere inside of either the beginning tag (for example
    Message 1 of 1 , Jan 13, 2003
    • 0 Attachment
      Ok then here it is Christine and anyone else interested. To use this clip put your mouse cursor somewhere inside of either the beginning tag (for example between the t and d of <td>) or inside the end tag (such as </td>). Then run the clip to select everything between the two tags, including the tags. You can have tables nested inside of other tables and it will still find the correct matching tag.. Or at least it has for me in the 8 months or so I've been using it.

      As usual, watch for broken lines in the clip as yahoo inserts its line breaks. Just remember each line in a clip command should begin with either a ^ or a : or a ;

      John

      ;-----------------------------------

      Matching Tags
      : SELECT MATCHING TAGS Hugo and John
      ; LAST MODIFIED: MONDAY, DECEMBER 30, 2002
      ^!SetScreenUpdate OFF
      ;-----------------------

      ^!ClearVariable %ISTHISAMISMATCH%

      ^!Jump SELECT_START
      :FINDTAG
      ^!find "<" BS
      :SETTAG
      ^!Set %TAG%=^$GetHtmlTagName("^$GetHtmlTag$";Lowercase)$
      ^!Set %STARTPOS%=^$GetRow$:^$GetCol$
      ^!IfTrue ^$StrPos("!";"^%TAG%";0)$ SELECTTAG
      ^!IfTrue ^$StrPos("/";"^%TAG%";0)$ ENDTAG
      ^!Find "/^%TAG%>" IS
      ^!IFERROR SELECTTAG
      :KEEPSEARCHING
      ^!Jump Select_END
      ^!SelectTo ^%STARTPOS%
      ^!Set %Selection%=^$GetSelection$
      ^!Set %FindNextMatch%=^$StrCount("<^%TAG%";"^%Selection%";0;1)$
      ^!Set %EndTagCount%=^$StrCount("</^%TAG%>";"^%Selection%";0;1)$
      ^!IF ^%FindNextMatch%<>^%EndTagCount% JUMPOVER
      ^!GoTO SELECTTAG
      :JUMPOVER
      ;-------------------------
      ^!If ^%FindNextMatch%-^%EndTagCount%=^%ISTHISAMISMATCH% THISISAMISMATCH
      ^!Set %ISTHISAMISMATCH%=^%FindNextMatch%-^%EndTagCount%
      ;-------------------------
      ^!Jump Select_END
      ^!Find "/^%TAG%>" IS
      ^!GoTo KEEPSEARCHING

      :THISISAMISMATCH
      ^!SetCursor ^%StartPOS%
      ^!MoveCursor 1
      ^!Select HTMLTAG
      ^!SetWizardTitle Tag mismatch. Review your code...
      ^!SetWizardLabel The corresponding tag could not be found!

      ; BEGIN ONE LONG LINE
      ^!Set %WhatNext%=^?{(T=L)Go to the last corresponding endtag?=_No, just select the tag that doesn't have a match^=No|Yes, and select anything in between^=Select|Yes, and insert corresponding tag after the selection^=Jump}
      ; END ONE LONG LINE

      ^!If ^%WhatNext%=No END
      ^!If ^%WhatNext%<>NO ^!Find <^%TAG\a*/^%TAG%> RS
      ^!If ^%WhatNext%=Jump ^!MoveCursor 1
      ^!If ^%WhatNext%=Jump ^!InsertTEXT ^%NL%<!--INSERTED NEW ENDTAG HERE-->^%NL%</^%TAG%>^%NL%^%NL%
      ^!GoTo END

      :FINDNoMATCH
      ^!SetCursor ^%ENDPOS%
      ^!MoveCursor -1
      ^!GoTo SELECTTAG

      :ENDTAG
      ^!Set %TAG%=^$strReplace("/";"";"^%TAG%";0;0)$
      ^!Find ">" IS
      ^!Jump Select_END
      ^!Set %ENDPOS%=^$GetRow$:^$getCol$
      :FindBeginningTag
      ^!Find "<^%TAG%" BIS
      ^!IFERROR STEPBACK
      ^!If "^$GetSelection$" = "<b" BR
      :NoBR
      ^!SelectTo ^%ENDPOS%
      ^!Set %Selection%=^$GetSelection$
      ^!Set %FindPrevious%=^$StrCount("</^%TAG%";"^%Selection%";0;1)$
      ^!IF ^%FindPrevious%>1 AGAIN
      ^!GOTO END
      :AGAIN
      ^!Jump Select_START
      ^!Dec %FindPrevious%
      ^!Find "<^%TAG%" BIS
      ;***** INSERTED ERRORCHECK
      ^!IfERROR FINDNoMATCH
      ^!SelectTo ^%ENDPOS%
      ^!IF ^%FindPrevious%>1 AGAIN

      ; BEGIN ONE LONG LINE
      ^!IF ^$StrCount("/^%TAG%>";"^$GetSelection$";0;0)$<>^$StrCount("<^%TAG%";"^$GetSelection$";0;0)$ AGAIN
      ; END ONE LONG LINE

      ^!GOTO END
      :STEPBACK
      ^!MoveCursor -1
      :SELECTTAG
      ^!If ^$GetSelSize$>3 END
      ^!Select HTMLTAG
      ^!STATUSSHOW Could not locate matching tag...
      ^!Delay 7
      ^!GoTo End

      ; BR TRAP TO NOT FALSE BOLD TAGS
      :BR
      ^!Select +2
      ^!If "^$GetSelection$" <> "<br>" NoBR
      ^!Jump SELECT_START
      ^!GoTo FindBeginningTag

      ;--------------------------------------------------------------------------
      ; Revision History
      ; SUNDAY, NOVEMBER 24, 2002
      ; Clip would fail if character entities were in the document.
      ; Added a / in the following line so it became:
      ; ^!Set %FindPrevious%=^$StrCount("</^%TAG%";"^%Selection%";0;1)$
      ;
      ; MONDAY, DECEMBER 30, 2002
      ; Noticed if searching backwards for a <b> tag when started from a </b> tag,
      ; the clip would fail if any <br> elements were in between the <b> </b> tags
      ; Added the BR trap to eliminate that.
    Your message has been successfully submitted and would be delivered to recipients shortly.