editor - should the app save the html content or markdown content into database? -


i building simple application, includes editing content such blog. have few options such tinymc, html editor, planned use it. find markdown, easy use , popular nowadays. among markdown supported editors, epiceditor choice.for reasons, wysiwygs sucks , complicated. decided use markdown editor.

then on node.js server side, have 2 choices store content, either in markdown or html, in cod, firstly parse markdown html, save 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 database is, app doesn't need parse markdown html when loading content. while advantage of saving markdown database is, when user want edit content again, easier client edit markdown content.

generally speaking, better preserve original input , transform (on demand) target view. lets present original input later editing, , transform original input different formats different views (for example, if wanted put data in email, leave markdown plain text text version of email).

that said, markdown html can costly (in terms of cpu) might want convert html when input (or when first viewed) , cache result (possibly in column in same database table markdown stored). should still keep original input though.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -