in reply to (jeffa) Re: HTML String Parsing
in thread HTML String Parsing
That module rocks!
Unfortunately, it doesn't do elimination of blank lines, which is the part that's giving me the trouble.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) 2Re: HTML String Parsing
by jeffa (Bishop) on Dec 10, 2001 at 02:22 UTC | |
Personally, i think you should use said module with the 'paras' arg instead of 'lines'. The reason is because the browser does an excellent job with text placement. If you are worried about width, just embed the resulting writeup in a <table>. Besides, 'paras' _does_ eliminate that unwanted white space. thraxil's solution is nice, by the way. Note how both \n and \r is accounted for. thraxil++ If you are still hell bent on using <br> tags then here is a hack i came up with, borrowing a little from thraxil and accounting for extra whitespace: The first regex replaces two or more newlines surrounding by possible other whitespace with a <p> on it's own line (and if you think that the two \s* thingies are unecessary, try this without em). I left out the trailing new line in the substitution because i just couldn't get a negative lookahead to work in the next regex. Hence, the third regex. I am sure that there is a way to use a negative lookahead to deprecate having to resort to the third regex, but I would just use HTML::FromText anyway! The second regex replaces all newlines that are not followed by a <p> tag with a <br> tag and newline. I would have rather liked for this to work: but as i said, this just didn't work. :( .o0(?)
UPDATE: jeffa | [reply] [d/l] [select] |
by Ionizor (Pilgrim) on Dec 13, 2001 at 11:33 UTC | |
The problem with tables is that they produce a crapload of HTML overhead. My site (http://mbn.dhs.org:81/) is really heavy on the tables already so I wanted to use the <BR> tags because they save a lot of space and bandwidth. The code produced by the script is actually just a list of comments included inside a table as an SSI. It's the comments page: http://mbn.dhs.org:81/comments.shtml I used thraxil's solution (you've been given credit in the script btw ;) because it's short, elegant, and easily understandable. The site is definitely a learning experience for me Perl-wise, which is why I've decided against using modules. The more programming I have to do the more I'll learn and the happier I'll be. It's not as though the site has a deadline or anything since I'm writing and running it to cater to a very limited group who don't really _need_ the site anyway. As for having it do exacly what I need it to do... I must admit to being a bit of a perfectionist. This occasionally gets me in trouble :) | [reply] |