I noticed from the docs that PageDown offers a refreshPreview
method. I'd like to turn off real-time editing and use this method to only do the conversion when the user presses a preview button.
I tried having the onPreviewRefresh
hook return false, but it still updates on every change event.
Here is my code:
$(document).ready(function() {
var converter = Markdown.getSanitizingConverter();
Markdown.Extra.init(converter, {table_class: "table table-striped"});
var editor = new Markdown.Editor(converter);
editor.hooks.chain("onPreviewRefresh", function () {
console.debug("the preview has been updated");
});
editor.run();
(function() {
$('#wmd-preview').hide();
$('button.preview').click(function() {
editor.refreshPreview();
$('#wmd-editor').hide();
$('#wmd-preview').show();
});
$('button.edit').click(function() {
$('#wmd-preview').hide();
$('#wmd-editor').show();
});
})();
});
Update:
Commenting out the following line (line 909 here) will actually accomplish what I want:
//timeout = setTimeout(makePreviewHtml, delay);
However, I'd be worried about unintended side effects, so I'd prefer a more surgical approach -- preferably one that doesn't require modifying the editor source code.