How to add a custom Markdown function to SimpleMDE?

*爱你&永不变心* 提交于 2019-12-04 00:54:16

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!