|
425 | 425 | return this;
|
426 | 426 | }
|
427 | 427 |
|
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; |
431 | 430 |
|
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); |
435 | 438 | } 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; |
445 | 440 | }
|
446 | 441 |
|
447 | 442 | return content;
|
|
452 | 447 | container = this.$textarea,
|
453 | 448 | afterContainer = container.next(),
|
454 | 449 | replacementContainer = $('<div/>',{'class':'md-preview','data-provider':'markdown-preview'}),
|
455 |
| - content; |
| 450 | + content, |
| 451 | + callbackContent; |
456 | 452 |
|
457 | 453 | // Give flag that tell the editor enter preview mode
|
458 | 454 | this.$isPreview = true;
|
459 | 455 | // Disable all buttons
|
460 | 456 | this.disableButtons('all').enableButtons('cmdPreview');
|
461 | 457 |
|
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(); |
463 | 462 |
|
464 | 463 | // Build preview element
|
465 | 464 | replacementContainer.html(content);
|
|
0 commit comments