// Ace Editor Loading
var editor = ace.edit("editor");
editor.setTheme("ace/theme/tomorrow");
editor.session.setMode("ace/mode/markdown");
editor.getSession().setUseWrapMode(true);
editor.setAutoScrollEditorIntoView(true);
editor.setOption("minLines", 10);
editor.setOption("maxLines", 25);

var textarea = $('textarea[id="body"]').hide();
var textarea_html_label = $('label[for="body_html"]').hide();
var textarea_html = $('textarea[id="body_html"]').hide();
textarea_html.val(marked(textarea.val()));
editor.getSession().setValue(textarea.val());
editor.getSession().on('change', function(){
  textarea_html.val(marked(editor.getSession().getValue()));
  textarea.val(editor.getSession().getValue());
});

// Hot Keys
editor.commands.addCommand({
    name: 'insert text',
    bindKey: {win: 'Ctrl-1',  mac: 'Ctrl-1'},
    exec: function(editor) {
        editor.insert("- [ ] TODO")
    },
    readOnly: true // false if this command should not apply in readOnly mode
});

editor.commands.addCommand({
    name: 'Insert TimeStamp',
    bindKey: {win: 'Ctrl-d',  mac: 'Ctrl-d'},
    exec: function(editor) {
        editor.insert(moment().format('MMMM Do YYYY, h:mm:ss a') + "\n");
    },
    readOnly: true // false if this command should not apply in readOnly mode
});

function showHTML() {
  $('#preview').html(marked(editor.getSession().getValue()));
}

editor.getSession().on('change', showHTML)

@@ -285,16 +285,287 @@
 , 25);%0A%0A
+// marked.js table renderer%0Avar renderer = new marked.Renderer();%0Arenderer.table = function (header, body) %7B%0A    return '%3Ctable class=%22table table-bordered%22%3E%3Cthead%3E' + header + '%3C/thead%3E%3Ctbody%3E' + body + '%3C/tbody%3E%3C/table%3E';%0A%7D;%0Amarked.setOptions(%7B renderer: renderer %7D);%0A%0A
 var text

Make markdown table pretty