Skip to content

Commit

Permalink
parseContent Fix
Browse files Browse the repository at this point in the history
Fixed a bug from parseContent method when used inside onPreview hook.

Added an optional argument val for some reason :)
  • Loading branch information
lodev09 committed Sep 16, 2014
1 parent e081bb4 commit 9e865ea
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions js/bootstrap-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,23 +426,17 @@
return this
}

, parseContent: function() {
var content,
callbackContent = this.$options.onPreview(this) // Try to get the content from callback

This comment has been minimized.

Copy link
@lodev09

lodev09 Sep 16, 2014

Author Owner

This will cause an endless execution if parseContent() is used inside onPreview hook.


if (typeof callbackContent == 'string') {
// Set the content based by callback content
content = callbackContent
, parseContent: function(val) {

This comment has been minimized.

Copy link
@lodev09

lodev09 Sep 16, 2014

Author Owner

Added the val argument to optionally pass a string to parse, if not given, use value from textarea

var content

// parse with supported markdown parser
var val = val || this.$textarea.val();
if(typeof markdown == 'object') {
content = markdown.toHTML(val);
}else if(typeof marked == 'function') {
content = marked(val);
} else {
// Set the content
var val = this.$textarea.val();
if(typeof markdown == 'object') {
content = markdown.toHTML(val);
}else if(typeof marked == 'function') {
content = marked(val);
} else {
content = val;
}
content = val;
}

return content;
Expand All @@ -453,14 +447,17 @@
container = this.$textarea,
afterContainer = container.next(),
replacementContainer = $('<div/>',{'class':'md-preview','data-provider':'markdown-preview'}),
content
content,
callbackContent

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

content = this.parseContent()
callbackContent = options.onPreview(this) // Try to get the content from callback
// Set the content based from the callback content if string otherwise parse value from textarea
content = typeof callbackContent == 'string' ? callbackContent : this.parseContent();

// Build preview element
replacementContainer.html(content)
Expand Down

0 comments on commit 9e865ea

Please sign in to comment.