我使用了 CKEditor 4.1.2 和 BBCode add-on 4.1.3,但我认为最新版本(4.3)并没有太大的不同。您需要做的所有更改都在 BBCode 插件中:
- YouTube 插件会创建 iframe,但我们需要将它们视为- youtubebbcode 的“标签”。所以添加- iframe: 'youtube'到第- convertMap30 行。
 
- 现在我们需要将该“标签”映射到 BBCode 标签。添加- youtube: 'youtube'到第- bbcodeMap29 行
 
- 现在我们需要指定如何处理这个- youtube标签。转到- editor.dataProcessor.htmlFilter.addRules(第 637 行)并- else if为- youtube标签添加新的:
 
代码:
else if (tagName == 'youtube') {
   element.isEmpty = 0;
   var arr = attributes.src.split('/');
   var ytid = arr[arr.length - 1].split('?')[0];
   element.children = [new CKEDITOR.htmlParser.text(ytid)];
   element.attributes.ytheight = attributes.height;
   element.attributes.ytwidth = attributes.width;
}
第一行是img标签的复制粘贴。我不确定它的作用。接下来的 3 行是从属性中获取 YouTube idsrc并放在youtube这样的标签之间[youtube]{id}[/youtube]。在 YouTube 标记中放置完整的 URL 是个坏主意,因为用户可以在其中放置任何 URL。请参阅约定:http ://www.bbcode.org/reference.php 。这个解决方案在你的情况下就足够了,但在我的情况下还不够。我也需要转移宽度和高度。所以最后 2 行添加了自定义属性ytheight和ytwidth. 我使用yt前缀,以便其他元素具有height或width不会将这些属性添加到它们的 BBCode 中。
4.转到var BBCodeWriter = CKEDITOR.tools.createClass(第 407 行)。在proto:(第 432 行)中有一个函数attribute : function( name, val )(第 486 行)添加一个else ifforytheight和一个ytwidth
代码:
else if (name == 'ytwidth') { 
    this.write(' width=', val); 
} else if (name == 'ytheight') {
    this.write(' height=', val);
}
如果需要,您可以通过这种方式添加更多属性。
最终输出:
[youtube height=315 width=560]0aSCPmabRpM[/youtube]
PS 这种方法的缺点是所有 iframe 都将被视为 YouTube,但我认为您不需要任何其他 iframe。