我想CKEditor在一个<p>元素中包含选定的单词.
从:
<p>This is a paragraph. And this is Selected text.</p>
Run Code Online (Sandbox Code Playgroud)
至:
<p>This is a paragraph. And this is</p>
<p class="myclass">Selected text.</p>
Run Code Online (Sandbox Code Playgroud)
我找到了一些代码:
( function() {
CKEDITOR.plugins.add( 'qna', {
init: function( editor ) {
editor.addCommand( 'insertQnA', {
exec : function( editor ) {
if(CKEDITOR.env.ie) {
editor.getSelection().unlock(true);
var selected_text = editor.getSelection().getNative().createRange().text;
} else {
var selected_text = editor.getSelection().getNative();
}
editor.insertHtml('[before]' + selected_text + '[after]');
}
});
editor.ui.addButton( 'qna', {
label: 'Insert QnA',
command: 'insertQnA',
icon: this.path + …Run Code Online (Sandbox Code Playgroud)