How to add a custom Markdown function to SimpleMDE?

后端 未结 1 1176
挽巷
挽巷 2021-02-13 14:25

Currently using this Markdown WYSIWYG editor. I needed to extend Markdown with one function (!!text!! to create red text) and have successfully done so on the serve

相关标签:
1条回答
  • 2021-02-13 14:48

    Try this:

    var myEditor = new SimpleMDE({
        toolbar: [
            {
                name: "redText",
                action: drawRedText,
                className: "fa fa-bold", // Look for a suitable icon
                title: "Red text (Ctrl/Cmd-Alt-R)",
            }
        ]
    });
    
    function drawRedText(editor) {
    
        var cm = editor.codemirror;
        var output = '';
        var selectedText = cm.getSelection();
        var text = selectedText || 'placeholder';
    
        output = '!!' + text + '!!';
        cm.replaceSelection(output);
    
    }
    

    You will have to add to the toolbar array the rest of the buttons you may need. Check them at the official GitHub repo.

    0 讨论(0)
提交回复
热议问题