0

Coding a blog website, using SimpleMDE (Markdown editor) for writing Markdown.

In app.js ,

//EDIT BLOG - FORM
app.get("/blog/:id/edit", function(req,res) {
    Blog.findById(req.params.id, function(err, foundBlog) {
        if(err) {
            res.redirect("/blog");
        } else {
            res.render("editBlog", {blog : foundBlog});
        }
    })
})

//UPDATE BLOG
app.put("/blog/:id", function(req,res) {
    req.body.blog.body = req.sanitize(req.body.blog.body);
    var id = req.params.id;
    Blog.findByIdAndUpdate(req.params.id, req.body.blog,{new: true}, function(err,updatedBlog) {
        if(err) {
            res.redirect("/blog");
        } else {
            res.render("showBlog", {blog : updatedBlog});
})

On using SimpleMDE, it works fine. enter image description here But on clicking the "Edit" button, the changes are saved as such: enter image description here

In editBlog.ejs,

    <div class="field">
    <label>Text</label>
    <textarea id="MyID" type="text" name="blog[body]"><%= blog.body %> </textarea>
  </div>

In showBlog.ejs,

<div id="main-blog-content"><%- blog.body %></div>

Am I missing something here?

4

1 回答 1

0

SimpleMDE 是为编写 Markdown 而设计的。因此,编辑器将在提交表单或访问内容时提供 Markdown。如果您希望将其转换为 HTML,则需要使用解析库来实现。如果要保持与预览窗口的一致性,SimpleMDE 使用标记。

下面是如何使用 SimpleMDE 的内置解析器将 Markdown 转换为 HTML:

var simplemde = new SimpleMDE();
var html = simplemde.markdown("**Example** text");
于 2017-03-02T15:25:47.467 回答