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?
For example
That isn't a problem with MongoDB, but you found out how HTML works :)
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).
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/
This has nothing to do with MongoDB. You get text from HTML textarea element and it has "new line" (\n
, \r
or \r\n
) characters as paragraph seperator. When you put it in HTML p elements, those new lines are interpreted as basic whitespaces. You should convert those "new line" characters into HTML br elements or put every text block into seperate p elements.
Check this npm package: https://www.npmjs.com/package/nl2br
You can easily code a better one.