Skip to content

Commit 846fb30

Browse files
committed
Vanilla patch of #103
1 parent ff65d9e commit 846fb30

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

js/bootstrap-markdown.js

+16-17
Original file line numberDiff line numberDiff line change
@@ -425,23 +425,18 @@
425425
return this;
426426
}
427427

428-
, parseContent: function() {
429-
var content,
430-
callbackContent = this.$options.onPreview(this); // Try to get the content from callback
428+
, parseContent: function(val) {
429+
var content;
431430

432-
if (typeof callbackContent == 'string') {
433-
// Set the content based by callback content
434-
content = callbackContent;
431+
// parse with supported markdown parser
432+
var val = val || this.$textarea.val();
433+
434+
if (typeof markdown == 'object') {
435+
content = markdown.toHTML(val);
436+
} else if (typeof marked == 'function') {
437+
content = marked(val);
435438
} else {
436-
// Set the content
437-
var val = this.$textarea.val();
438-
if(typeof markdown == 'object') {
439-
content = markdown.toHTML(val);
440-
}else if(typeof marked == 'function') {
441-
content = marked(val);
442-
} else {
443-
content = val;
444-
}
439+
content = val;
445440
}
446441

447442
return content;
@@ -452,14 +447,18 @@
452447
container = this.$textarea,
453448
afterContainer = container.next(),
454449
replacementContainer = $('<div/>',{'class':'md-preview','data-provider':'markdown-preview'}),
455-
content;
450+
content,
451+
callbackContent;
456452

457453
// Give flag that tell the editor enter preview mode
458454
this.$isPreview = true;
459455
// Disable all buttons
460456
this.disableButtons('all').enableButtons('cmdPreview');
461457

462-
content = this.parseContent();
458+
// Try to get the content from callback
459+
callbackContent = options.onPreview(this);
460+
// Set the content based from the callback content if string otherwise parse value from textarea
461+
content = typeof callbackContent == 'string' ? callbackContent : this.parseContent();
463462

464463
// Build preview element
465464
replacementContainer.html(content);

0 commit comments

Comments
 (0)