in reply to Re: regex problem...
in thread regex problem... parsing html font tags

alright, everyone keeps telling me to use HTML::Parser...but i need to match each opening font tag with the correct closing font tag...see, for each font tag, i substitute code that sets the font color, font size, and font face seperately, so i also need to end the color, size, and face stylings seperately. to do that, i need to match each opening font tag with the closing font tag that directly follows it. how would i do that with HTML::Parser? I've read through the pod documentation, and i don't see how i could do that...

Replies are listed 'Best First'.
Re: Re: Re: regex problem...
by Anonymous Monk on Oct 09, 2001 at 11:27 UTC
    well, i think i can do it, but in this code:
    $p = HTML::Parser->new(api_version => 3, start_h => [sub { ... }, "self,tagname,attr,text"], );
    how do i replace the starting font tag *and* the text contained in the font tags with something generated in sub { ... }?
      What you'd probably want to do is setup handlers for end tags and text, and have all handlers append to a string the text you want them replaced with or the original the text if you don't want them replaced.

      For handling ending FONT tags, you can catch the end of tag event and insert the appropriate ending tag. If the ending tag may vary you can keep (an) array(s) indicating what type of ending tag(s) to use (each element telling you information for one tag), push onto them when you encounter a start FONT tag, and pop off them when you encoutner an end FONT tag and output the appropriate tags.

      (update: last paragraph rewritten)