问题描述
我使用以下配置CKEditor:
var wysiwyg = ck.replace(el [0],{
allowedContent:true,
protectedSource:[/ \r | \\\
/ g]
});
我在CKEditor中加载HTML源代码:
< 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按照来源保持缩进? / p>
我试图在 protectedSource
中使用不同的regex来保护HTML 。 like
/(?:\>)([^<] *?)(?: \ 但没有运气。 p>
不,不是。内容在返回给您之前,会经过解析器,过滤器,作者和浏览器的DOM多次。您不能期望保留每个在内容方面不重要的选项卡或空格字符。请记住,CKEditor不是代码编辑器 - 它是一个所见即所得的编辑器。
I'm using following config for CKEditor:
var wysiwyg = ck.replace(el[0], {
allowedContent: true,
protectedSource: [/\r|\n/g]
});
I'm loading HTML source into CKEditor as:
<div style='font-weight: bold;'>
<div>
<div> test </div>
</div>
</div>
On wysiwyg.getData()
I receive:
<div style="font-weight: bold;">
<div>
<div>test</div>
</div>
</div>
How can I force CKEditor to keep my indentation as per source?
I tried to use different regex inside protectedSource
to protect everything between HTML >...<
like /(?:\>)([^<]*?)(?:\<)/g
https://regex101.com/r/eV4dO0/1 but without luck.
No, it isn't. Content is passed through parsers, filters, writers and browser's DOM many times before it returns to you. You cannot expect to preserve every single tab or space character which is not significant in terms of the content. Please remember that CKEditor is not a code editor - it is a WYSIWYG editor.
这篇关于CKEditor:保持源缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!