Let \n (newline) in strings passed to ui elements (e.g. label) be automatically translated to </br> #5570
Replies: 4 comments 4 replies
-
|
Hello @whoamiafterall Sorry that will NOT be implemented because that could also mean other HTML will be honored, which is all sorts of dangerous (think But then we have CSS+Tailwind to the rescue: CSS explaination: https://dev.to/cassidoo/make-line-breaks-work-when-you-render-text-in-a-react-or-vue-component-4m0n Tailwind style explanation: https://tailwindcss.com/docs/white-space#pre-line Shown in action: ui.label('Multiline\nLabel\nExample').classes('whitespace-pre-line')
Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
|
Finally: While Pythonic and IDE warning is a fair point, I think we should also respect the web nature of NiceGUI, so I would not recommend any library-side adjustments. While whitespace pre-wrap is like the second result on Google on respecting \n, I think we can also do better in our docs, since multiline label is likely a frequent demand. |
Beta Was this translation helpful? Give feedback.
-
I don't think replacing "\n" with "<br />" would be a security risk. The user would only be able to add line breaks, nothing else. But I also don't think we should change the behavior of a plain |
Beta Was this translation helpful? Give feedback.
-
Hey, thank you for pointing that out.
Also the tailwind class is an interesting solution. I ended up using ui.markdown however, as you said. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
I noticed that passing \n to e.g. a ui.label() would not be translated to a newline in the resulting html.
It would make the feeling a bit more pythonic if that was possible. Also Because IDE's don't warn you about it.
Example Use Case (Don't Judge please) 🥹
(If you're wondering, i'm letting the user write some .md files in their nextcloud and i cache them on the server)
Beta Was this translation helpful? Give feedback.
All reactions