保留<pre> tag whitespace when displaying content from Firebase with dangerouslySetInnerHtml

时间:2017-06-16 20:35:49

标签: reactjs firebase

Here's the background: I want to be able to save rich text blog posts to Firebase to then display them, including code snippets, on a Posts page.

Right now, I'm simply saving a single string of html to Firebase, retrieving that per post, and setting it with dangerouslySetInnerHtml. I'm the only one adding posts.

However, this means that I lose tabbing information when displaying code snippets in blocks. I don't think I can use solution since I'm using dangerouslySetInnerHtml: Formatting code with <pre> tag in React and JSX

Any tips on how to store, retrieve, and display rich text using React and Firebase? Thank you for your help.

1 个答案:

答案 0 :(得分:0)

我能够使用以下内容将富文本转换为html,然后缩小它: