简体   繁体   English

以已解析的形式将BBCode插入CKEditor

[英]Insert BBCode into CKEditor's in parsed form

Let's say I have a button on a webpage that when pressed, inserts specific $text formatted with BBCode into CKEditor. 假设我在网页上有一个按钮,当按下该按钮时,会将使用BBCode格式化的特定$ text插入CKEditor。 It's easy to make the $text be inserted in unparsed form with this line: 通过以下这一行很容易使$ text以未解析的形式插入:

CKEDITOR.instances.message.insertText(text);

But how can I make the $text be inserted in already parsed form? 但是如何使$ text以已解析的形式插入? .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. .insertHtml以与insertText相同的形式粘贴。我确实知道它的HTML格式,但是找不到其他插入函数,所以我尝试了这个。

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. 当您执行CTRL + C和CTRL + V时,您将粘贴已分析的表单。

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. 它使用fromBBCode方法将BBCode转换为htmlParser的片段。

Ok thanks to @oleq CKEditor documentation and source code of a custom made js found somewhere I've found a solution. 好的,感谢@oleq CKEditor文档以及在我找到解决方案的地方找到的定制js的源代码。

@oleq solution only works for parsing tags without additional properties. @oleq解决方案仅适用于解析标签而没有其他属性。 so [quote] [url] etc. not [quote="something"] [url="http://] 因此[quote] [url]等,而不是[quote="something"] [url="http://]

This one line should parse and insert all content from var text: 这一行应解析并插入var文本中的所有内容:

clickableEditor.Insert(text, bbcodeParser.bbcodeToHtml(text));

Found this in custom files from plugin MyBB CKEditor. 在插件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: 在MyBB论坛上具有CKEditor插件的用户还可以使用:

MyBBEditor.insertText(your_variable);

Let me know if this has some flaws or something I forgot about - like exceptions? 让我知道这是否存在一些缺陷或我忘记的东西-例如异常?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM