bootstrap-markdown
bootstrap-markdown copied to clipboard
Initializing with JavaScript doesn't work
Hello
I came across your repo and wanted to try it out. If it works smoothly, custom cool features can be easily integrated into this editor. But I'm stuck at the start. The editor works fine when the data-provide="markdown"
attribute is present, but if I remove it then nothing happens. Also, calling the plugin via JavaScript doesn't seem to work:
$("#content").markdown({
autofocus: false,
savable: false,
iconlibrary: 'fa',
resize: 'vertical',
additionalButtons: custom_buttons, // an array defining custom commands
onPreview: function (e) {
var content = e.getContent();
console.log('content', content);
}
});
Any ideas what might be the case? I've already put in markdown.js
and to-markdown.js
, which weren't mentioned in the docs but it was a quick find anyway.
Is this project dead? I'd like to help and see others chip in to resolve the issues and implement extra functions like an image gallery, image upload, inserting code blocks etc.
For some reason, changing the order of JavaScript references fixed it. Here's the order now:
-
lib/markdown.js
-
lib/bootstrap-markdown.js
-
lib/to-markdown.js
And here's my code for initializing and setting up the editor so far:
$(function () {
var custom_buttons = [[
{
name: "insertCode",
data: [{
name: "cmdInsertCode",
toggle: "toggle",
title: "Insert Code",
icon: "fa fa-fire",
callback: function (e) {
var selected = e.getSelection(),
content = e.getContent();
// e.replaceSelection(chunk);
// var cursor = selected.start;
//e.setSelection(cursor, cursor + chunk.length);
console.log('cmdInsertCode clicked');
}
}]
}
]];
$("#content").markdown({
autofocus: false,
savable: false,
iconlibrary: 'glyph',
resize: 'vertical',
additionalButtons: custom_buttons,
onShow: function (e) {
console.warn('e:editor shown');
}
});
});
Will update if I come across any other issues of this sort :godmode:
Did you also include the bootstrap.js file ? I am kind of stuck with the
TypeError: element.markdown is not a function
When trying to use this library as follows:
$('textarea').each(function(index, element) {
console.log('Textarea', element);
element.markdown({autofocus:false,savable:false})
});