I'm currently working on a small personal project that involves converting HTML and plain text to a semi-proprietary markup language. I have several tables of HTML tags that must be converted, and am trying to devise the most efficient way to perform this task without completely reinventing the wheel.

So far, I've looked at Parse::RecDescent and Template, but these don't seem to have the "search & replace" functionality that I need. RecDescent has no problems finding specific tags, but I have not been able to find out how to perform a replacement that affects the text passed in to the parser. It's simple enough to write a grammar rule that matches a <html> tag, but I don't know what to do in the action portion of the rule. If I act on @item, the changes aren't reflected in the original text.

Template Toolkit also seems a bit limited for what I'm doing. It obviously has the search and replace functionality, but I don't seem to be able to find any way to specifiy specific search and replace pairs.

I know that I can throw all of my search and replace pairs into a great big hash and loop, but this seems to be a far cry from the best answer.


Is there something in Parse::RecDescent or Template Toolkit that I'm missing? Is there some other module available that will let me do search and replace in the manner that I need? I did quite a bit of research on CPAN, but it's entirely possible that I missed something. And before anybody makes the statement, no there are no convertors or modules available for the markup language I'm using.

Guildenstern
Negaterd character class uber alles!

In reply to Search & Replace Parsing? by Guildenstern

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.