【问题标题】:CKEditor: Keep source indentationCKEditor:保持源缩进
【发布时间】:2022-01-22 01:07:27
【问题描述】:

我正在为 CKEditor 使用以下配置:

var wysiwyg = ck.replace(el[0], {
  allowedContent: true,
  protectedSource: [/\r|\n/g]
});

我正在将 HTML 源代码加载到 CKEditor 中:

<div style='font-weight: bold;'> 
  <div> 
    <div> test </div> 
  </div>
</div>

wysiwyg.getData() 我收到:

<div style="font-weight: bold;">
<div>
<div>test</div>
</div>
</div>

如何强制 CKEditor 根据来源保持缩进?

我尝试在 protectedSource 中使用不同的正则表达式来保护 HTML &gt;...&lt; 之间的所有内容,例如 /(?:\&gt;)([^&lt;]*?)(?:\&lt;)/g https://regex101.com/r/eV4dO0/1 但没有运气。

【问题讨论】:

标签: javascript ckeditor


【解决方案1】:

我想保持源格式不变。这可能吗?

不,不是。内容在返回给您之前会多次通过解析器、过滤器、编写器和浏览器的 DOM。您不能期望保留在内容方面不重要的每个制表符或空格字符。请记住,CKEditor 不是代码编辑器——它是一个所见即所得的编辑器。

【讨论】:

    【解决方案2】:

    请将 CKeditor 的这两行添加到配置文件中

    config.protectedSource = [/\r|\n/g];
    config.allowedContent = true;
    

    【讨论】:

      猜你喜欢
      • 2018-08-13
      • 1970-01-01
      • 1970-01-01
      • 2012-12-08
      • 2014-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多