CKEditor: Keep source indentation

依然范特西╮ 提交于 2020-01-16 13:21:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!