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

Re: [NH] match html tag

Expand Messages
  • Don - htmlfixit.com
    next version ... works forward or backward I think my screen problem is fixed by not turning wordwrap off ;*** Effort by Don Passenger ;*** don@htmlfixit.com
    Message 1 of 10 , Jan 11, 2005
    • 0 Attachment
      next version ... works forward or backward I think
      my screen problem is fixed by not turning wordwrap off

      ;*** 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]If cursor is in the tag you want to find a match for click
      continue

      ;### initialize everything
      ;assume we have our cursor in a tag
      ;look backwards to find the starting <
      ^!Find "<" TIBS
      ;exit if find fails
      ^!IfError EXIT
      ^!SetScreenUpdate Off
      ^!ClearVariables

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


      ;### So we found a tag. What tag is it?
      ^!Set %TAGNAME%="^$GetHtmlTagName("^%TAG%";UPPERCASE)$"
      ;got to forwards or backwards routine depending if
      ;start or finish tag is selected at start of clip
      ^!If "/" = "^$StrCopyLeft("^%TAGNAME%";1)$" FindNextTagBackwards ELSE
      FindNextTagForwards

      :FindNextTagForwards
      ^!Jump Select_Start
      ;figure out where cursor is
      ^!Set %row%="^$GetRow$"
      ^!Set %column%="^$GetCol$"
      ^!Find ">" TIS
      ^!Set %TAGCOUNT%=1
      :TagForwardLoop
      ^!Find "<" TIS
      ^!IfError UnMatched
      ^!Set %TAGTEMP%="^$GetHtmlTag(TRUE)$"
      ^!IfTrue ^$IsEmpty(^%TAGTEMP%)$ NextTag
      ^!Set %TAGTEMPNAME%="^$GetHtmlTagName("^%TAGTEMP%";UPPERCASE)$"
      ^!If "/" = "^$StrCopyLeft("^%TAGTEMPNAME%";1)$" EndTag ELSE BeginTag

      :EndTag
      ^!If "^$StrDeleteLeft("^%TAGTEMPNAME%";1)$" <> "^%TAGNAME%" Skip_2
      ^!Dec %TAGCOUNT%
      ^!If "^%TAGCOUNT%" = "0" Match
      ^!Goto NextTag

      :BeginTag
      ^!If "^%TAGTEMPNAME%" <> "^%TAGNAME%" Skip_2
      ^!Inc %TAGCOUNT%
      ^!If "^%TAGCOUNT%" = "0" Match
      ^!Goto NextTag

      :NextTag
      ^!Jump Select_End
      ^!Goto TagForwardLoop


      :FindNextTagBackwards
      ^!Jump Select_End
      ;figure out where cursor is
      ^!Set %row%="^$GetRow$"
      ^!Set %column%="^$GetCol$"
      ^!Find "<" TIBS
      ^!Set %TAGCOUNT%=1
      :TagBackwardLoop
      ^!Find "<" TIBS
      ^!IfError UnMatched
      ^!Set %TAGTEMP%="^$GetHtmlTag(TRUE)$"
      ^!IfTrue ^$IsEmpty(^%TAGTEMP%)$ NextTag2
      ^!Set %TAGTEMPNAME%="^$GetHtmlTagName("^%TAGTEMP%";UPPERCASE)$"
      ^!If "/" = "^$StrCopyLeft("^%TAGTEMPNAME%";1)$" EndTag2 ELSE BeginTag2

      :EndTag2
      ^!If "^%TAGTEMPNAME%" <> "^%TAGNAME%" Skip_2
      ^!Inc %TAGCOUNT%
      ^!If "^%TAGCOUNT%" = "0" Match
      ^!Goto NextTag2

      :BeginTag2
      ^!If "^%TAGTEMPNAME%" <> "^$StrDeleteLeft("^%TAGNAME%";1)$" Skip_2
      ^!Dec %TAGCOUNT%
      ^!If "^%TAGCOUNT%" = "0" Match
      ^!Goto NextTag2

      :NextTag2
      ^!Jump Select_START
      ^!Goto TagBackwardLoop



      :Match
      ^!SetScreenUpdate On
      ^!Info [C]Bingo, we have a match!.
      ^!If "/" = "^$StrCopyLeft("^%TAGNAME%";1)$" MatchBackwardJump ELSE
      MatchForwardJump
      :MatchForwardJump
      ^!Jump SELECT_END
      ^!Goto MatchFinish
      :MatchBackwardJump
      ^!Jump SELECT_START
      :MatchFinish
      ^!SelectTo ^%row%:^%column%
      ^!Goto Finish

      :UnMatched
      ^!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


      :NotTag
      ^!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


      :SelfClosing
      ^!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
      :Finish
      ^!SetScreenUpdate On
      ^!ClearVariables
      ;line 137 if you have all lines unrapped (including blank lines)
    • Adrian/ Rosemary Worsfold
      FindNextTagBackwards line is given as an error in mine. It s another good idea deleted after trying it. Adrian Worsfold http://www.pluralist.co.uk
      Message 2 of 10 , Jan 14, 2005
      • 0 Attachment
        FindNextTagBackwards

        line is given as an error in mine.

        It's another good idea deleted after trying it.

        Adrian Worsfold

        http://www.pluralist.co.uk
      • Don - htmlfixit.com
        ... Hey Adrian, Were you using my clip? I tested it forwards and backwards and it worked fine. I strongly suspect a wrapped line. I would appreciate help
        Message 3 of 10 , Jan 15, 2005
        • 0 Attachment
          Adrian/ Rosemary Worsfold wrote:
          > FindNextTagBackwards
          >
          > line is given as an error in mine.
          >
          > It's another good idea deleted after trying it.
          Hey Adrian,

          Were you using my clip? I tested it forwards and backwards and it
          worked fine. I strongly suspect a wrapped line. I would appreciate
          help figuring out if something is broken with it so I can get a working
          copy out. The other one suggested seemed to work well also.

          Don
        • hsavage
          ... Adrian, Are you sure that long word didn t get wrapped down to the next line in email. Several lines were wrapped when I copied the clip to a clipbook and
          Message 4 of 10 , Jan 15, 2005
          • 0 Attachment
            Adrian/ Rosemary Worsfold wrote:
            > FindNextTagBackwards
            >
            > line is given as an error in mine.
            >
            > It's another good idea deleted after trying it.
            >
            > Adrian Worsfold

            Adrian,

            Are you sure that long word didn't get wrapped down to the next line in
            email. Several lines were wrapped when I copied the clip to a clipbook
            and the word 'FindNextTagBackwards' was wrapped to a line by itself.

            ºvº
            05.01.15
            hrs > hsavage@...
          • Adrian/ Rosemary Worsfold
            ... Yes. I look for broken lines but can t always detect them. It s gone now. Adrian Worsfold http://www.pluralist.co.uk
            Message 5 of 10 , Jan 17, 2005
            • 0 Attachment
              >Were you using my clip? I tested it forwards and backwards<

              Yes. I look for broken lines but can't always detect them. It's gone now.

              Adrian Worsfold

              http://www.pluralist.co.uk
            Your message has been successfully submitted and would be delivered to recipients shortly.