如何向SimpleMDE添加自定义Markdown功能? [英] How to add a custom Markdown function to SimpleMDE?

查看:410
本文介绍了如何向SimpleMDE添加自定义Markdown功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前使用 Markdown WYSIWYG编辑器。我需要使用一个函数扩展Markdown( !! text !! 来创建红色文本)并且已经在服务器端成功完成了,但作为一个与JavaScript斗争的人,我在为这个库做同样的事情时遇到了困难。

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 server side, but as one who struggles with JavaScript, I'm having difficulty doing the same for this library.

推荐答案

试试这个:

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);

}

您必须在工具栏数组中添加其余部分您可能需要的按钮。请在官方GitHub回购中查看它们。

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

这篇关于如何向SimpleMDE添加自定义Markdown功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆