javascript - 在 CKEditor 中保留 SCRIPT 标签(以及更多)

标签 javascript regex exception ckeditor source-code-protection

是否有可能在 CKEditor 中创建一个不会被编辑器本身触及的代码块,并且在用户明确更改之前将保持其预期状态?我一直在尝试输入 javascript 变量(绑定(bind)在脚本标签中)和随后的 flash 电影,但 CKEditor 继续重写我粘贴的代码/标记,并在这样做时破坏了我的代码。

我正在使用以下设置:

<script type="text/javascript">
  var editor = CKEDITOR.replace("content", {
    height : "500px",
    width : "680px",
    resize_maxWidth : "680px",
    resize_minWidth : "680px",
    toolbar :
    [
      ['Source','-','Save','Preview'],
      ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
      ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
      ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
      ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
      ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
      ['Link','Unlink','Anchor'],
      ['Image','Table','HorizontalRule','SpecialChar']
    ]
  });
  CKFinder.SetupCKEditor( editor, "<?php print url::base(); ?>assets/ckfinder" );
</script>

我想最理想的解决方案是保留任何包含 class="preserve" 的标签的内容,这比有限的排他性要多得多。

更新:我认为这个问题的解决方案在 CKEDITOR.config.protectedSource() 中,但事实证明我的正则表达式经验太幼稚,无法处理这个问题。我将如何避免所有包含“保留”类的标签被 CKEditor 触及?

最佳答案

在 CKEDITOR 文件夹中,您有一个 config.js 文件。打开它并粘贴代码:

CKEDITOR.editorConfig = function( config ) {
    config.allowedContent = {
        script: true,
        $1: {
            // This will set the default set of elements
            elements: CKEDITOR.dtd,
            attributes: true,
            styles: true,
            classes: true
        }
    };
};

它将允许 <script>...</script>源代码模式下的标签。

关于javascript - 在 CKEditor 中保留 SCRIPT 标签(以及更多),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1739552/

相关文章:

javascript - 当类型是 map 的任何成员时提高 Typescript 速度?

javascript - 无法设置未定义的属性 'running'

JavaScript OR on if 语句

regex - PCRE 正则表达式 空格

.net - .NET 是否有类似于 Delphi 的 EAbort 的异常?

javascript - 使用 javascript 和 asp.net 启用和禁用按钮

python - 如何将 BeautifulSoup HREF 搜索从 <a> 扩展到 <td>

python - 在 python 中评论正则表达式

java - 在Java中使用异常处理强制用户输入字符(字母)而不是字符串

java - NAO Robotics学生在AMD 64位平台上编译错误: Can't load IA 32-bit . dll