I'm working on code to render HTML automatically from text files.
What I'd like is for a text file containing just linebreaks and some special characters to be rendered as HTML by some regexes.
I need to do three things:
- render some special-character shortcuts as bold and italic, i.e. in
this is
i italic
text
the line which starts with an i-space gets rendered as italics.
-
I also need to do some multi-line ones, ( see 266313 ) to render lists.
- My final wish is to render the content, if it's not in one of those lists, into HTML-compliant paragraphs (at the moment it's just a bunch of text in a TD with double-BR-tags separating the "paragraphs").
So I can hack together regexes for each one of those, but I'm in TMTOWTDI mode at the moment, pondering various ways of doing it.
I could work on the lines of the text file as an array, I could put them together as one long string, or I could do a bit of both -- say do the single-line ones iterating over the string then join() and do the multi-line ones.
What do monks think?
Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.
M-J D
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.