I’m currently developing this in Python (with web.py) on Windows, and using latest Chrome.
Simple test:
- User is shown a basic web form with a component.
- When form is submitted, the content of this textarea is placed into a MySql table, unmodified.
- Later, the user returns to edit their last submission.
- I then present a new form, with the textarea populated directly from the database for modification – HTML is prevented from being processed so tags are displayed.
- However, when re-displayed to the user, every line now has an extra (unwanted) line-break between each line.
How can I prevent this?
eg:
Submitted Text:
Line 1
Line 2
When re-displayed, the text looks like:
Line 1
Line 2
I’m aware that this is going to be some kind of CR LF issue but can’t quite get to the solution.
I tried a conversion to <br /> but that just displays the <br /> text not an actual line break.
I don’t really want to modify the text before putting it into the database either.
But I guess I do need something that would compensate for various OS that display line breaks differently.
I’ve read through many of the similar questions here, but they are primarily PHP, or talk about nl2br which wouldn’t be a solution here anyway.
If you are using
printto output the text, append a comma at the end of your statement to remove the new-line character.e.g.
It may be that a new-line is already in your printed text and doesn’t require the extra appended one from print.
If not, try
.rstrip('\n')on your string to remove any new-lines.