简体   繁体   English

保 <pre> 在显示来自Firebase的内容时带有危险的标签空白

[英]Preserving <pre> tag whitespace when displaying content from Firebase with dangerouslySetInnerHtml

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. 背景如下:我希望能够将RTF博客文章保存到Firebase,然后在“帖子”页面上显示它们,包括代码片段。

Right now, I'm simply saving a single string of html to Firebase, retrieving that per post, and setting it with dangerouslySetInnerHtml. 现在,我只是将一个html字符串保存到Firebase,每个帖子检索该字符串,然后使用危险地设置InnerHtml进行设置。 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 我不认为可以使用解决方案,因为我正在使用危险地使用SetInnerHtml: 在React和JSX中使用<pre>标签格式化代码

Any tips on how to store, retrieve, and display rich text using React and Firebase? 关于如何使用React和Firebase存储,检索和显示RTF的任何提示? Thank you for your help. 谢谢您的帮助。

I was able to use the following to convert rich text to html, and then minify it: 我可以使用以下内容将富文本格式转换为html,然后将其最小化:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM