html - CKEditor - 当我在源代码 View 和所见即所得 View 之间切换时,HTML 代码不断添加新行?

标签 html jinja2 ckeditor4.x

我试图在 CKEditor 中保留我的 jinja 代码,就像在代码 View 和 WYSIWYG View 之间切换 View 之后一样。

我可以通过在我的 config.js 文件中添加以下行来得到这个结果

CKEDITOR.config.protectedSource.push(/\r|\n/g);

CKEDITOR.config.autoParagraph = false;

但是,它不适用于 HTML 代码。例如,如果 jinja 代码和 html 像这样混合在一起:

{% if name=='bob' %}
    {{'hello bob'}}
{%else%}
    {{ 'hello ' + name }} 
{% endif %}

<p>Hello visitor</p>

这是关于 Fiddle JS 的演示

在此之后,当我在 CKEditor 中从代码 View 更改为 wyiwyg View 时,HTML 代码只增加了一个新行,另一个切换 View 增加了另一行,如下所示:

enter image description here

我找不到 HTML 代码有什么问题,我只是格式化 jinja 代码,我该如何解决?谢谢

最佳答案

在你的代码下面写下这些额外的行

$("body").on("click", ".cke_button__source", ()=>{
//   if(CKEDITOR.instances.editor1.mode==="source"){
     let vtk = CKEDITOR.instances.editor1.getData();
    // vtk = vtk.replace(/\n<p>/gm, "<p>");
     vtk = vtk.replace(/^\s*[\r\n]/gm, "");
     $(".cke_source").val(vtk)
  // }
})

Here is jsFiddle

关于html - CKEditor - 当我在源代码 View 和所见即所得 View 之间切换时,HTML 代码不断添加新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54609365/

相关文章:

python - webapp2,Jinja2 : how to cut large html file into multiple html files

Ansible/神社 : how to convert number to binary format

javascript - 将参数值组合到 Jquery 中的变量名

javascript - CKEditor 图标路径不是 URLEncoded

javascript - 在移动 Chrome 上禁用 Canvas 元素上的默认上下文菜单。 (我在 Android Chrome 上试过)

html - 如何强制样式 HTML 元素?

python - Jinja2 中带有相关变量的 For 循环

javascript - ckeditor 4 在提交数据时添加额外的间距

javascript - $ ('label' ).css ('width' ) 在 Chrome 中返回错误值

javascript - 响应图像 slider 居中图像