How to create a Mongoose schema that saves input as html in mongodb

天涯浪子 提交于 2019-12-24 19:29:57

问题


I am creating a blog website with an admin panel in which a user can write the body of the blog's content in the text editor tinyMCE. Currently my schema for blog body is set to string but everytime I write a blog you can see the html marks around the blog and the markup is not recognized as html. Is this an issue with the schema being set to string?


回答1:


I use it in my projects in a similar way. I save tinyMCE content to mongo as a string and thus is saved with the html tags. If you want display these contents out of tinyMCE editor you have to make the template language output the unescaped value into the template. Lets say that your data are stored as description. If you use ejs you can display it without html tags using this <%- description %>.



来源:https://stackoverflow.com/questions/54188389/how-to-create-a-mongoose-schema-that-saves-input-as-html-in-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!