Simplemde-markdown-editor: Extend the default toolbar (without overriding default icons)

Created on 2 Oct 2017  路  4Comments  路  Source: sparksuite/simplemde-markdown-editor

From the documentation, we can provide our own array of toolbar icons, however doing so we override the default icons.

I'd like to extend the default toolbar with some extra icons I provided in this way:

{
    name: "custom",
        action: function customFunction(editor){},
    className: "fa fa-star",
    title: "Custom Button",
}

Is it possible to do this with the current codebase? Reading the code I didn't see a way to do so.
Thank you.

Most helpful comment

I found a tricky solution

mde.gui.toolbar.remove()
mde.toolbar.push({
  name: 'metadata',
  action: function() {},
  className: 'fa fa-tags',
  title: 'Metadata'
})
mde.createToolbar()

All 4 comments

const toolbar = [
      'bold', 'italic', 'heading', '|',
      'code', 'quote', 'unordered-list', 'ordered-list', '|',
      'link',
      {
        name: 'image',
        action: function customFunction(editor) {
          alert('This feature is not implemented yet.');
        },
        className: 'fa fa-picture-o',
        title: 'Insert Image',
      },
      'table', '|',
      'preview', 'side-by-side', 'fullscreen', '|',
      {
        name: 'Help',
        action: function customFunction(editor) {
          alert('This feature is not implemented yet.');
        },
        className: 'fa fa-keyboard-o',
        title: 'Editor Sortcuts',
      },
      {
        name: 'Help',
        action: function customFunction(editor) {
          alert('This feature is not implemented yet.');
        },
        className: 'fa fa-question-circle',
        title: 'Editor Help',
      },
      '|', // Separator
    ];

instance = new SimpleMDE({
        element: this.textarea.nativeElement,
        toolbar: this.toolBarSetting(),
      });

This is the easiest way to do this.

I used the example of @CWharton, but needed to modify the last statement to toolbar: toolbar, to make it work.

I found a tricky solution

mde.gui.toolbar.remove()
mde.toolbar.push({
  name: 'metadata',
  action: function() {},
  className: 'fa fa-tags',
  title: 'Metadata'
})
mde.createToolbar()

Trick

        var simplemde = new SimpleMDE();
    simplemde.toolbar.push(
        {
            name: "upload",
            action: function customFunction(){
                console.log("hola")
            },
            className: "fa fa-upload",
            title: "upload Files",
            id: "upload-button"
        }
    );
    var tools = simplemde.toolbar;
    simplemde.toTextArea();
    simplemde = null;
    var mde = new SimpleMDE({
        element: document.getElementById("editor1"),
        spellChecker: false,
        autosave: {
            enabled: true,
            unique_id: "editor",
        },
        toolbar: tools,
    });

Works for me!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

keioka picture keioka  路  5Comments

christianmalek picture christianmalek  路  5Comments

asvae picture asvae  路  3Comments

abr4xas picture abr4xas  路  3Comments

andrelgarcia picture andrelgarcia  路  4Comments