Handling spaces with user input

The only reason I include Python in the question is: PHP has a function nl2brthat inserts tags br, a similar function in Python may be useful, but I suspect that this problem can be solved using HTML and CSS.

So, I have a form that takes user input in a text box. I save it in the database, which is Postgres, and then when I show it, it does not include the line that interrupts the user provided to the individual paragraphs.

enter image description here

I tried using the CSS property white-spacein the paragraph tag:

white-space: pre

or

white-space: pre-wrap

But this is strange, the result was highlighted lines, but the first line is aligned in the middle:

enter image description here

including text-align:leftdoes not solve the problem. I am sure there is a simple solution.

+4
1

<br /> ( ), (. ).

Python:

import re
myUserInput = re.sub('(?:\r\n|\r|\n)', '<br />', myUserInput)

JavaScript (. jsfiddle):

myUserInput = myUserInput.replace(/(?:\r\n|\r|\n)/g, '<br />');
+4

Source: https://habr.com/ru/post/1547973/


All Articles