是否有可能在 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/