Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Having a checkbox, or possibly autodetect sounds like a good idea. When the user is using HTML, don't apply any other formatting, but let the user take full responsibility. Save the choice as a boolean in the database as well,so you know what processing, if any, to make when it is time to produce output.

Another option is to disallow <p> and <br>, so you can make replacements in all of them, but that is probably not so popular. Or to make it harder on yourself, try to guess what to do, ie /<br>\n/ does not get replaced, while a single \n will. Probably not a good route.

In some kinda-similar solutions I've also had both types of data saved side-by-side in the database, especially when there would be a lot of processing overhead otherwise. DB size is rarely *that* important, after all. This could be useful in that when somebody saves a pure-text post, you also save a HTML version, but you still have the pure text for the email etc.

Trying to format texts back and forth might be a bad idea, lots of special cases and whatnot. A one-off conversion from one to the other should probably be much more reliable in the long run. At least any bugs should be easily spotted and fixed, as opposed to a text that has gone from HTML to text to HTML to... if your users can edit posts for instance, that could happen really fast. :)


You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue.

In reply to Re: Converting plain text to HTML and back again by Dog and Pony
in thread Converting plain text to HTML and back again by Nomis52

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 examining the Monastery: (4)
As of 2024-04-25 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found