Let's say I have a button on a webpage that when pressed, inserts specific $text formatted with BBCode into CKEditor. It's easy to make the $text be inserted in unparsed form with this line:
CKEDITOR.instances.message.insertText(text);
But how can I make the $text be inserted in already parsed form? .insertHtml pastes in same form as insertText.I do know its for Html but couldn't find any other insert function, so I tried this one.
CKEDITOR.instances.message.insertHtml(text);
What is the name of the function that pastes the thing with preparsing? When you do CTRL+C and CTRL+V, you paste the parsed form.
Anyone got ideas?
You could try this one:
var writer = new CKEDITOR.htmlWriter();
CKEDITOR.htmlParser.fragment.fromBBCode( '[b]Bold[/b]' ).writeHtml( writer );
CKEDITOR.instances.message.insertHtml( writer.getHtml() );
It uses fromBBCode method to convert BBCode into htmlParser's fragment.
Ok thanks to @oleq CKEditor documentation and source code of a custom made js found somewhere I've found a solution.
@oleq solution only works for parsing tags without additional properties. so [quote] [url]
etc. not [quote="something"] [url="http://]
This one line should parse and insert all content from var text:
clickableEditor.Insert(text, bbcodeParser.bbcodeToHtml(text));
Found this in custom files from plugin MyBB CKEditor. Based on code:
MyBBEditor = {
insertText: function(a)
{
if(clickableEditor.editor.mode == 'wysiwyg')
{
clickableEditor.Insert(a, bbcodeParser.bbcodeToHtml(a));
}
else
{
clickableEditor.performInsert(a);
}
}
}
Users that have CKEditor plugin on their MyBB forum can also use:
MyBBEditor.insertText(your_variable);
Let me know if this has some flaws or something I forgot about - like exceptions?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.