Highlight text with TinyMCE

跟風遠走 提交于 2021-01-28 12:20:51

问题


Currently I have a textarea using TinyMCE: http://fiddle.tinymce.com/D2gaab

I want to highlight the text between the opening/closing braces. Does someone know if this is possible, and how I can do this?


回答1:


You could consider inserting a <mark> tag, or another element with inline styling. Also, maybe only insert when the selection has any length.

 editor.addButton('spintax', {
  text: 'Spintax',
  icon: false,
  onclick: function () {
    editor.focus();
    if (editor.selection.getContent().length) {
        editor.selection.setContent("{<mark>" + editor.selection.getContent() + '</mark>}');
    }
  }
});

http://fiddle.tinymce.com/E2gaab



来源:https://stackoverflow.com/questions/52976156/highlight-text-with-tinymce

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