45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
autosize(document.getElementsByTagName('textarea'));
|
|
|
|
var md = markdownit({
|
|
html: true,
|
|
xhtmlOut: true,
|
|
highlight: function (str, lang) {
|
|
hljs.configure({
|
|
tabReplace: ' '
|
|
});
|
|
if (lang && hljs.getLanguage(lang)) {
|
|
try {
|
|
return hljs.highlight(lang, str).value;
|
|
} catch (__) {}
|
|
}
|
|
|
|
return ''; // use external default escaping
|
|
}
|
|
});
|
|
|
|
function liveUpdate(e) {
|
|
|
|
}
|
|
|
|
document.getElementById('post_content').addEventListener('input', function(e) {
|
|
document.getElementById('preview').innerHTML = md.render(this.value);
|
|
});
|
|
|
|
document.getElementById('post_content').addEventListener('keydown', function (e) {
|
|
// Allow use of tab key for indentation
|
|
if (e.keycode == 9 || e.which == 9) {
|
|
e.preventDefault();
|
|
//e.stopPropagation();
|
|
var s = this.selectionStart;
|
|
this.value = this.value.substring(0,this.selectionStart) + "\t" + this.value.substring(this.selectionEnd);
|
|
this.selectionEnd = s+1;
|
|
}
|
|
|
|
document.getElementById('preview').innerHTML = md.render(this.value);
|
|
});
|
|
document.getElementById('preview').innerHTML = md.render(document.getElementById('post_content').value);
|
|
|
|
})(); |