CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
HTML/Text Wrapping

 



dmittner
Novice

May 1, 2002, 4:41 PM

Post #1 of 5 (2620 views)
HTML/Text Wrapping Can't Post

I'm working on a communications area on a system I'm building for my company and I'm running into a snag. When a message is written, it's done so in a textarea field and it's saved into the database with a substition for the endlines. When it's read, it's pulled out, the endlines are substituted back in, the Text::Wrap module wraps it to 80 characters and the endlines are substituted for HTML line breaks. This works well as long as the text isn't HTML. I would like to have support for HTML and the wrapping to take it into consideration, ie. the length of an 'a href' line wouldn't be figured into the 80 characters and only the displayed portion would.

Does anyone know of a module which would be able to do this? I've looked on cpan and couldn't find anything that stuck out as a solution. I guess I could get into writing my own, but I'd rather not put the time towards it.



Thanks,

Dave Mittner


fashimpaur
User / Moderator

May 2, 2002, 5:20 AM

Post #2 of 5 (2617 views)
Re: [dmittner] HTML/Text Wrapping [In reply to] Can't Post

dmittner,

Isn't it possible to take the text returned by the Text::Wrap object do
a substitution of line breaks with html breaks instead? Actually, I can
guess that you'd have to do several substitutions (i.e. "\n\n" is replaced with
<P>, all remaining "\n" characters would be replaced with <BR>, etc.).

If the text is input as html, do a reverse replacement to store it in the DB.
You may need a separate feild in the database to tell you what the original
input came in as (i.e. text or html).

HTH,
Dennis

$a="c323745335d3221214b364d545".
"a362532582521254c3640504c3729".
"2f493759214b3635554c3040606a0",
print unpack"u*",pack "h*",$a,"\n\n";


dmittner
Novice

May 2, 2002, 9:02 AM

Post #3 of 5 (2613 views)
Re: [fashimpaur] HTML/Text Wrapping [In reply to] Can't Post

Well.. the substitution element is already taken care of and not really a problem. The problem comes in when Text::Wrap tries to figure out 80 character lines. It takes information between the '<' and '>' and figures that in as well even though that isn't something that would be viewable. The result is unexplainably short lines, to the naked eye.


gregarios
stranger

Jun 2, 2002, 12:16 AM

Post #4 of 5 (2587 views)
Re: [dmittner] HTML/Text Wrapping [In reply to] Can't Post

I had the same problem with a forum I created. I ended up just outputting the text into tables of the correct width and let the HTML output wrap itself. I then implemented the Text:Wrap on each word in the output individually and wrapped any words that were longer than 80 characters, but only if they didn't start with "http//".

Greg J Piper
[url=http://www.macpicks.com]MacPiCkS



dmittner
Novice

Jun 2, 2002, 3:22 AM

Post #5 of 5 (2584 views)
Re: [gregarios] HTML/Text Wrapping [In reply to] Can't Post

Well... I think I made a routine which does the wrapping I want. It's maybe not the prettiest code, but it gets the job done seemingly well. It basically goes through a string character by character and toggles between being in an 'html' mode or not. If it's in it, then the number of characters until it exits aren't factored into the 80 limit. Like I said, not perfect and not full proof, but works well for simply formatted texts.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives