2

I am now building a simple application, which includes editing the content such as blog. I have a few options such as tinymc, a good html editor, which I planned to use it. but then I find something about markdown, which is easy to use and popular as well nowadays. among the markdown supported editors, EpicEditor is a good choice.For some reasons, WYSIWYGs sucks and complicated. so I decided to use markdown editor.

Then on the node.js server side, I have two choices to store the content, either in markdown or html, as in the cod, it firstly parse the markdown into html, then save it to the database.

app.post('/post', function(req, res){
    var currentUser = req.session.user,
        html = markdown.makeHtml(req.body.post),
        post = new Post(currentUser.name, req.body.title, html);
    post.save(function(err){
        if(err){
            req.flash('error', err); 
            return res.redirect('/');
        }
        req.flash('success', 'scc!');
        res.redirect('/');
    });
});

the advantage of saving html to database is, the app doesn't need to parse from markdown to html when loading the content. while the advantage of saving markdown to database is, when the user want to edit the content again, it is easier for the client to edit the markdown content.

Oscar Godson
  • 31,662
  • 41
  • 121
  • 201
user824624
  • 7,077
  • 27
  • 106
  • 183
  • Define "better". Without clarification, better is subjective and meaningless, and the question is unanswerable. – Christian Apr 18 '13 at 15:35

1 Answers1

3

Generally speaking, it is better to preserve the original input and then transform it (on demand) for the target view. That lets you present the original input back for later editing, and transform from the original input to different formats for different views (for example, if you wanted to put the data in an email, you could leave the markdown as plain text for the text version of the email).

That said, Markdown to HTML can be costly (in terms of CPU) so you might want to convert to HTML when it is input (or when first viewed) and then cache the result (possibly in another column in the same database table as the markdown is stored). You should still keep the original input though.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335