markdown-live-preview/public/js/main.js

34 lines
784 B
JavaScript
Raw Permalink Normal View History

2011-05-16 20:26:21 +04:00
$(function() {
2020-10-23 18:24:28 +03:00
var isEdited = false;
2020-10-23 18:24:28 +03:00
// Setup editor
var editor = ace.edit('editor');
editor.getSession().setUseWrapMode(true);
editor.setOptions({
maxLines: Infinity,
indentedSoftWrap: false,
fontSize: 14,
theme: 'ace/theme/github',
// TODO consider some options
});
2020-08-10 16:32:13 +03:00
2020-10-23 18:24:28 +03:00
editor.on('change', () => {
isEdited = true;
convert();
2019-02-16 17:50:49 +03:00
});
2020-10-23 18:24:28 +03:00
let convert = () => {
let html = marked(editor.getValue());
let sanitized = DOMPurify.sanitize(html);
$('#output').html(sanitized);
}
2020-10-23 18:24:28 +03:00
//leave
$(window).bind('beforeunload', function() {
if (isEdited) {
return 'Are you sure you want to leave? Your changes will be lost.';
}
});
2020-07-17 19:31:22 +03:00
2020-10-23 18:24:28 +03:00
convert();
2020-08-14 16:35:54 +03:00
});