防止 Jinja 代码在 CKEditor 4 中换行?

Prevent Jinja code from wrapping into one single line in CKEditor 4?

我正在使用 CKEditor 4.x 用于 jinja html 模板代码。因此,我尝试在 CKEditor 的源代码视图中将其配置为支持 jinja 语言。

出于这个考虑,我希望编辑器不要将我的 jinja 代码包装成一行。例如,如果我在编辑器的源视图中写如下:

{% if name=='hello' %}
    {{ 'hello' }} 
{%else%}
    {{ 'what is your name?' }} 
{% endif %}

然后我切换所见即所得视图并再次返回源代码,我希望它与上面的代码相同。

但是,目前它将上面的代码包装成一行,如下所示:

{% if name=='hello' %}{{ 'hello' }} {%else%} {{ 'what is your name?' }} {% endif %}

这是我当前的 config.js 文件:

/**
 * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
 * For licensing, see https://ckeditor.com/legal/ckeditor-oss-license
 */

CKEDITOR.editorConfig = function( config ) {
    // Define changes to default configuration here. For example:

    config.removePlugins = 'easyimage, cloudservices';
    config.height = 800;
    config.toolbarCanCollapse = true;

    /* skin */
    config.skin = 'office2013';

    config.extraPlugins = 'codemirror,placeholder,textindent,floating-tools,textselection,tableresizerowandcolumn,quicktable';
    // 1. Codemirror
       config.codemirror = {
         // Define the language specific mode 'htmlmixed' for html  including (css, xml, javascript), 'application/x-httpd-php' for php mode including html, or 'text/javascript' for using java script only 
        mode: 'django',

    };

    config.toolbar = 'Basic';


};

/* Protected code in editor */
CKEDITOR.config.protectedSource.push(/<\?[\s\S]*?\?>/g); // PHP

CKEDITOR.config.protectedSource.push(/\{\%[\s\S]*?\%\}/g); // Jinja {% %}

// CKEDITOR.config.protectedSource.push(/\{\{[\s\S]*?\}\}/g); // Jinja {{ }}

CKEDITOR.config.protectedSource.push(/\{\#[\s\S]*?\#\}/g); // Jinja {# #}

CKEDITOR.config.autoParagraph = false;

正如我所希望的那样,在CKEditor配置设置中必须有一个配置我们可以设置以存档上述效果。请帮我存档。谢谢。

已添加:

我已经用 summernote 编辑器测试了相同的情况,它在这里工作如我所愿,但出于某种原因我更喜欢 CKEditor 而不是 summernote。我不清楚在 codemirror 或编辑器本身中设置的此配置。谢谢。

非常感谢,经过几个小时的搜索,我设法自己找到了解决方案。这很简单。为了存档上述结果,我尝试将其添加到我的 config.js 文件中,它按我的意愿工作:

CKEDITOR.config.protectedSource = [/\r|\n/g];

希望这对像我一样遇到问题并找到解决方案的人有所帮助。谢谢