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

RE: [NH] match html tag

Expand Messages
  • Greg Chapman
    ... I tend to use TIDY s formatted (indented) output to see the location of matching closing tags. It s not perfect, but does what I need. Greg
    Message 1 of 10 , Jan 10, 2005
      > > Does NoteTab have a feature that matches or finds a beginning tag with
      > > its end tag.
      > > Most useful would be <Table and /Table>
      >
      > No it doesn't to my knowledge.

      I tend to use TIDY's formatted (indented) output to see the location of
      matching closing tags.

      It's not perfect, but does what I need.

      Greg
    • Don - htmlfixit.com
      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
      Message 2 of 10 , Jan 10, 2005
        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
        ^!ClearVariables


        ;### %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
        FindNextTagForwards

        :FindNextTagForwards
        ^!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
        ^!Info [C]End Tag
        ^!If "^$StrDeleteLeft("^%TAGTEMPNAME%";1)$" <> "^%TAGNAME%" Skip_2
        ^!Dec %TAGCOUNT%
        ^!If "^%TAGCOUNT%" = "0" Match
        ^!Goto NextTag

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

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

        ^!Jump Select_End
        ^!Goto FindNextTagForwards


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



        :Match
        ^!SetScreenUpdate On
        ^!SetWordWrap On
        ^!Info [C]Bingo, we have a match!.
        ^!Jump SELECT_END
        ^!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
        ^!SetWordWrap On
        ^!ClearVariables
        ;line 110 if you have all lines unrapped (including blank lines)
      • 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 3 of 10 , Jan 11, 2005
          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 4 of 10 , Jan 14, 2005
            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 5 of 10 , Jan 15, 2005
              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 6 of 10 , Jan 15, 2005
                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 7 of 10 , Jan 17, 2005
                  >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.