How do I store/display paragraphs with mongodb?

后端 未结 2 1337
青春惊慌失措
青春惊慌失措 2021-01-01 02:04

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

2条回答
  •  有刺的猬
    2021-01-01 02:46

    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.

提交回复
热议问题