Prevent CKEditor from formatting code in source mode

前端 未结 5 714
没有蜡笔的小新
没有蜡笔的小新 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条回答
  • config.allowedContent=true; will do the trick

    Here is the full HTML code

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title>CKEditor</title>
            <script src="http://cdn.ckeditor.com/4.5.10/standard/ckeditor.js"></script>
        </head>
        <body>
            <textarea name="editor1"></textarea>
            <script>
                CKEDITOR.config.allowedContent=true;
                CKEDITOR.replace( 'editor1' );
            </script>
        </body>
    </html>
    
    0 讨论(0)
  • 2021-02-05 07:41

    Does this answer help? Basically you can turn off the options adding a javascript, it looks like.

    0 讨论(0)
  • 2021-02-05 07:43

    I solved this problem by simply surrounding the back-end output of edit form page with a conditional on a $_GET variable - when you click on "Expert Mode" it loads a plain textarea instead of the ckeditor system. Your invocation of the ckeditor object will vary depending on your setup. ( I have a custom class that calls/builds the editor object )

                    <div id="postdivrich" class="postarea">
    <?php
    if( isset( $_GET['expert'] ) )
    {
        print "<div style=\"text-align:right;\"><a href=\"/admin/ckeditor/edit.php?node={$nNode}\">Editor mode</a></div>\n";
        print "<textarea name=\"content\" style=\"height:400px;width:{$nEwidth}px;\">{$aDoc['content']}</textarea>\n";
    }
    else
    {
        print "<div style=\"text-align:right;\"><a href=\"/admin/ckeditor/edit.php?node={$nNode}&expert=true\">Expert mode</a></div>\n";
        require_once( 'admin/editor.class.php' );
        $aDoc['content'] = str_replace( "\r", '', str_replace( "\n", '', nl2br( $aDoc['content'] ) ) );
        $oEditor = new setEditor( $aDoc['content'], $nEwidth, "400", 'content' );
        $oEditor->ShowEditor();
    }
    ?>
                    </div>
    
    0 讨论(0)
  • 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('<!-- src -->','<!-- end src -->'),array('<protected>','</protected>'),$content);
    

    Before saving the resulting content:

    $content = str_replace(array('<protected>','</protected>'),array('<!-- src -->','<!-- end src -->'),$content);
    

    In the CKEditor configuration:

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

    Hope that helps!

    0 讨论(0)
  • 2021-02-05 08:03

    I wanted to preserve newlines in my source, and the protectedSource feature works well for that. I added this to my config.js:

    config.protectedSource = [/\r|\n/g];
    
    0 讨论(0)
提交回复
热议问题