Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the markdown lib dependencies as a default and editable option #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions js/bootstrap-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
textarea.addClass('md-input')
editor.append(textarea)
} else {
var rawContent = (typeof toMarkdown == 'function') ? toMarkdown(container.html()) : container.html(),
var rawContent = options.htmlToMarkdown(container.html()),
currentContent = $.trim(rawContent)

// This is some arbitrary content that could be edited
Expand Down Expand Up @@ -313,14 +313,7 @@
content = callbackContent
} else {
// Set the content
var val = container.val();
if(typeof markdown == 'object') {
content = markdown.toHTML(val);
}else if(typeof marked == 'function') {
content = marked(val);
} else {
content = val;
}
content = options.markdownToHtml(container.val())
}

// Build preview element
Expand Down Expand Up @@ -632,7 +625,7 @@
// Build the original element
var oldElement = $('<'+editable.type+'/>'),
content = this.getContent(),
currentContent = (typeof markdown == 'object') ? markdown.toHTML(content) : content
currentContent = options.markdownToHtml(content)

$(editable.attrKeys).each(function(k,v) {
oldElement.attr(editable.attrKeys[k],editable.attrValues[k])
Expand Down Expand Up @@ -909,6 +902,20 @@
],
additionalButtons:[], // Place to hook more buttons by code

// Markdown Adapter
htmlToMarkdown: function(html) {
return typeof toMarkdown === 'function' ? toMarkdown(html) : html
},
markdownToHtml: function(md) {
if (typeof markdown === 'object') {
return markdown.toHTML(md)
} else if (typeof marked === 'function') {
return marked(md)
} else {
return md
}
},

/* Events hook */
onShow: function (e) {},
onPreview: function (e) {},
Expand Down