JSFiddle:http: //jsfiddle.net/92z35/2/
我有一个目前运行良好的 Pagedown 编辑器,除了我必须以编程方式插入一些内容的少数情况。如果我插入然后键入,则预览会更新。但如果我只是插入,预览保持不变。
我错过了什么?
代码:
var converter = Markdown.getSanitizingConverter();
converter.hooks.chain("preBlockGamut", function (text, rbg) {
return text.replace(/^ {0,3}""" *\n((?:.*?\n)+?) {0,3}""" *$/gm, function (whole, inner) {http://jsfiddle.net/BcuLq/#run
return "<blockquote>" + rbg(inner) + "</blockquote>\n";
});
});
var editor = new Markdown.Editor(converter);
ko.bindingHandlers.wysiwyg = {
init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
editor.hooks.chain("onPreviewRefresh", function () {
$(element).change();
});
editor.run();
}
};
var ViewModel = function(first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
this.fullName = ko.computed(function() {
return this.firstName() + " " + this.lastName();
}, this);
this.appendText = function(){
$("#wmd-input").val($("#wmd-input").val() + '@')
}
};
ko.applyBindings(new ViewModel("Planet", "Earth"));