【发布时间】:2020-10-29 10:29:38
【问题描述】:
我目前正在构建我的第一个博客站点,我正在使用 CKEditor v4.14.1 来允许用户制作格式化的博客条目。但是,用户输入在网页上显示为 HTML 而不是格式化文本。我也在使用 MongoDB 来存储博客条目。
这是用户输入:
这是网页上的输出:
new.ejs
<form action="/posts" method="POST" enctype="multipart/form-data">
<div class="input-area">
<textarea name="post[body]" id="editor" placeholder="Body"></textarea>
</div>
<input type="submit" id="submit">
</form>
<script>
CKEDITOR.replace('editor')
</script>
MongoDB 发布架构
const PostSchema = new Schema({
body: String
})
PostSchema.plugin(mongoosePaginate)
module.exports = mongoose.model('Post', PostSchema);
控制器/posts.js
const Post = require('../models/post');
// Posts Create
async postCreate(req, res, next) {
let post = new Post(req.body.post);
post.body = req.body.post.body;
await post.save();
}
show.ejs
<div><%= post.body %></div>
【问题讨论】:
标签: javascript html node.js mongodb ckeditor