Prevent CKEditor from formatting code in source mode

前端 未结 5 715
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 07:31

How can you prevent any automatic formatting when in CKEditor when viewing in source mode?

I like to edit HTML source code directly instead of using the WYSIWYG

5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 07:52

    My solution to this was to use comments in my system, but before feeding the page content to CKEditor, convert them to custom HTML tags. Then, upon save, convert them back to my comment tags.

    For your syntax that would be something like this in PHP. Before printing the page content to the textarea:

    $content = str_replace(array('',''),array('',''),$content);
    

    Before saving the resulting content:

    $content = str_replace(array('',''),array('',''),$content);
    

    In the CKEditor configuration:

    protectedSource:[/[\s\S]*<\/protected>/g]
    

    Hope that helps!

提交回复
热议问题