问题
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.
回答1:
I would like to keep the source formatting as it is. Is this possible?
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.
来源:https://stackoverflow.com/questions/29603854/ckeditor-keep-source-indentation