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

32 lines
725 B
JavaScript
Raw Normal View History

2011-05-16 20:26:21 +04:00
$(function() {
var isEdited = false;
2020-08-10 16:32:13 +03:00
let convert = () => {
let html = marked($('#markdown').val());
2020-08-14 15:56:03 +03:00
let sanitized = DOMPurify.sanitize(html);
$('#output').html(sanitized);
2020-08-10 16:32:13 +03:00
}
$('#markdown').bind('keyup', function() {
isEdited = true;
2020-08-10 16:32:13 +03:00
convert();
2019-02-16 17:50:49 +03:00
$('#output a').each(function(index, element) {
var href = element.getAttribute('href');
if (RegExp('^javascript', 'i').test(href)) {
element.setAttribute('href', '#');
}
});
});
//autoresize
$('textarea').autosize();
2013-02-17 09:43:20 +04: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-08-10 16:32:13 +03:00
convert();
2020-08-14 16:35:54 +03:00
});