ckeditor-在所选文本上切换标记

时间:2018-07-28 10:10:00

标签: javascript ckeditor

我需要通过自定义标签在CKEditor中标记所选文本,例如{{ }}
我已经做到了:
JavaScript

var answerContent = CKEDITOR.replace('editor', {
    toolbarGroups: [
        {"name":"basicstyles","groups":["basicstyles"]},
        {"name":"paragraph","groups":["list"]},
        {"name":"examiner","groups":["examiner"]}
    ],
    removeButtons: 'Underline,Strike,Subscript,Superscript,Anchor,Styles,Specialchar'
});

answerContent.addCommand("markPhraseToFill", {
    exec: function(edt) {
        var selectObj = edt.getSelection();
        var selectedText;
        var startTag = '{{';
        var endTag = '}}';

        if (CKEDITOR.env.ie) {
            selectObj.unlock(true);
            selectedText = selectObj.getNative().createRange().text;
        } else {
            selectedText = selectObj.getNative();
        }

        edt.insertHtml(startTag + selectedText + endTag);
    }
});

answerContent.ui.addButton('ExaminerBtnMarkPhrase', {
    label: "Mark phrase",
    command: 'markPhraseToFill',
    toolbar: 'examiner',
    icon: 'http://placehold.it/16x16'
});

但是现在我需要将此按钮设置为“切换like B”标记等。
怎么做?
JSFiddle DEMO

0 个答案:

没有答案