Fork me on GitHub
#reagent
<
2017-09-30
>
stvnmllr214:09:29

Can't find the words to search for the answer to this. How do you put content with newlines in a div, and convert newlines to <br/>. Or is there a better solution for displaying multi-line user entered content?

naomarik14:09:58

@stvnmllr2 [:pre] preserves whitespace

stvnmllr214:09:04

@naomarik True, but doesn't wrap.

reefersleep14:09:11

Maybe this is also helpful?

reefersleep14:09:57

Bet you could get a pre to wrap with css, though

juhoteperi14:09:28

white-space: pre-wrap

juhoteperi14:09:54

(it is css rule)

stvnmllr214:09:02

Thanks. That does seem to work. Pre with css. Now.. looking at the markdown cljs to see how to handle other types of user entered content.

stvnmllr214:09:18

Went back to the markdown example, and they use :dangerouslySetInnerHTML of react. So I guess that is an alternative if to create html content and put it in your hiccup:

[:div {:dangerouslySetInnerHTML
             {:__html (md->html help)}}]

juhoteperi14:09:51

Yes, or convert newlines to hiccup

juhoteperi15:09:06

(into [:div] (interpose [:br] (str/split "\n" string-with-newlines)))