Reputation: 199
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.
But on clicking the "Edit" button, the changes are saved as such:
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?
Upvotes: 0
Views: 486
Reputation: 2933
SimpleMDE is designed for writing Markdown. As such, the editor will provide Markdown when a form is submitted or when the content is accessed. If you're looking to convert it to HTML, you'll need to do so with a parsing library. SimpleMDE uses marked, if you want to maintain consistency with the preview window.
Here's how to use SimpleMDE's built-in parser to convert Markdown to HTML:
var simplemde = new SimpleMDE();
var html = simplemde.markdown("**Example** text");
Upvotes: 0