问题描述
我知道mongo不是用于格式化的,但是我如何创建博客帖子并以段落形式显示它而不是一小段文字呢?
I understand that that mongo is not for formatting, but how can I create a blog post and display it in paragraph form without it being one block of text?
例如,如果我有一个管理部分,可以在其中创建博客文章,然后将其输入到textarea部分...
For example, if I have an admin section where I can create blog posts and I enter this into the textarea portion...
奉献的教养精英,劳动者和社会保障组织的圣贤. Ut enim ad minim veniam,quis nostrud 进行ullamco labour锻炼会导致commodo后果. Duis aute irure dolor in reprehenderit in voltate velit esse cillum dolore eu fugiat nulla pariatur.
Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
奉献的教养精英,劳动者和社会保障组织的圣贤. Ut enim ad minim veniam,quis nostrud 进行ullamco labour锻炼会导致commodo后果. Duis aute irure dolor in reprehenderit in voltate velit esse cillum dolore eu fugiat nulla pariatur.
Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
它显示为...
推荐答案
MongoDB没问题,但是您发现了HTML的工作原理:)
That isn't a problem with MongoDB, but you found out how HTML works :)
提交文本区域时,所有换行符都是发送到服务器的换行符(\n
或\r\n
).它们按原样存储在数据库中.
但是,在HTML中,表示文本时,换行符被忽略并被视为空格(除非您将换行符包装在<pre></pre>
块中).
When you submit a textarea, all newlines are simply newline characters sent to the server (\n
or \r\n
). They are stored in the database as is.
However, in HTML newlines are ignored and considered like spaces, when representing text (unless you wrap that in a <pre></pre>
block).
解决方案是用<br />
标签替换所有\n
.如果您熟悉PHP,它将使用nl2br
函数,该函数已在以下位置移植到JavaScript: http://phpjs.org/functions/nl2br/
The solution is to replace all \n
with <br />
tags. If you're familiar with PHP, it would be using the nl2br
function, which has been ported to JavaScript here: http://phpjs.org/functions/nl2br/
这篇关于如何使用mongodb存储/显示段落?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!