CKEditor:保持源缩进
CKEditor: Keep source indentation
我正在为 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 >...<
之间的所有内容,例如 /(?:\>)([^<]*?)(?:\<)/g
https://regex101.com/r/eV4dO0/1 但没有成功。
I would like to keep the source formatting as it is. Is this possible?
不,不是。内容在 returns 之前通过解析器、过滤器、编写器和浏览器 DOM 多次传递给您。您不能期望保留每个制表符或 space 字符,这些字符在内容方面并不重要。请记住,CKEditor 不是一个代码编辑器——它是一个所见即所得的编辑器。
请将 CKeditor 的这两行添加到配置文件
config.protectedSource = [/\r|\n/g];
config.allowedContent = true;
我正在为 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 >...<
之间的所有内容,例如 /(?:\>)([^<]*?)(?:\<)/g
https://regex101.com/r/eV4dO0/1 但没有成功。
I would like to keep the source formatting as it is. Is this possible?
不,不是。内容在 returns 之前通过解析器、过滤器、编写器和浏览器 DOM 多次传递给您。您不能期望保留每个制表符或 space 字符,这些字符在内容方面并不重要。请记住,CKEditor 不是一个代码编辑器——它是一个所见即所得的编辑器。
请将 CKeditor 的这两行添加到配置文件
config.protectedSource = [/\r|\n/g];
config.allowedContent = true;