Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-16 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found