Reformatting pasted text
December 31, 2006 7:05 AM   Subscribe

Coding question: What is the best/easiest way to preserve typographical formatting (like nbsp's, line breaks) of pasted text that will be stored in a database and later displayed in boxes of arbitrary size?

The problem is not exactly that I can't do this, just that the current method is incredibly anal and cludgy--I am overthinking this. The end result should be having text displayed so that scaling the dimensions of the box (w/ javascript) keeps all the paragraphs and doesn't have the text overflow, and doesn't require computing the pixels of all the letters on a line..
posted by shownomercy to Computers & Internet (6 answers total) 1 user marked this as a favorite
Is this text preformatted or is the browser going to do wordwrapping?

Fixed or variable width font?

Is this code? Prose? Something else?
posted by Khalad at 8:31 AM on December 31, 2006

Response by poster: This text is preformatted arbitrarily as it is user submitted, and then probably some magic reformats it to get rid of arbitrary line breaks etc. Should work for prose and code and poetry. Essentially I don't want to cause problems with different browsers with how it's displayed.
posted by shownomercy at 8:45 AM on December 31, 2006

Hm, I'm not clear on what you're trying to do exactly. How about an easy question: why is plain text insufficient? It would preserve spacing and line breaks.
posted by Khalad at 9:08 AM on December 31, 2006

Strip any undesired formatting. Insert your own nbsp and html tags where desired, then store that plain text in the database. When pulled out of the database, drop it into it's own div and let browser handle all of the formatting. Easy peasy.
posted by Roger Dodger at 12:53 PM on December 31, 2006

Whatever you do, keep in mind what "nbsp" stands for, and what that means. Many people just think "oh, it's a space" when in fact, it's more than just a regular space.
posted by secret about box at 1:14 AM on January 1, 2007

If you're caught up on scaling the size of the box along with the text and keeping them relatively correct, look into sizing the box & text using ems instead of pixels.
posted by tmcw at 12:06 PM on January 1, 2007

« Older How to meet people and make friends at a party   |   Why can't I format my SD card? Newer »
This thread is closed to new comments.