[ic] reverse text2html filter for easier editing

Christian Brink interchange-users@icdevgroup.org
Mon Jun 23 02:48:01 2003


> Is there a html2text filter? If so, how would I apply
> this in the admin within the flex_editor page? Would I
> have to create a special widget with a filter built-in
> or something like that? I've tried grepping for
> 'text2html' and have also searched through
> /ic/lib/UI/usertag/filters.tag but haven't come up
> with something that has been done already.

Well I was going to tell you to there were many examples if you Google for
them, but after taking a look at what is out there I would recommend
against it (the crap that people pass off). All the ones I have seen rely
on regexps to parse HTML.

Your best bet is to use Ovid's module HTML-TokeParser-Simple.
http://search.cpan.org/author/OVID/HTML-TokeParser-Simple-2.1/Simple.pm

It's easy and (more importantly) correctly parses html. You can then
determine what to replace the html tag with using a simple case-like
statement.

$_ = $tag_type;   # from HTML::TokeParser::Simple
CASE:
{
   /br/ and do { $current_text .= "\n"    };  # A break tag
   /a/  and do { $current_text .= 'LINK:' };  # An anchor tag
   /p/  and do { $current_text .= "\n\n"  };  # A paragraph tag
   ...                                        # and so on
}

You can write a simple module to do what you need and create a user tag. I
wrote an email to the list not to long ago about writing a user tag (It
may not be the best way, but it works for me).

HTH

Christian
http://www.perlmonks.com/index.pl?node_id=133383
http://search.cpan.org/author/GREP/
http://www.yoda-speak.org/