繁体   English   中英

如何在wysiwyg编辑器中保持html属性不变?

[英]How to keep html attribute unchanged in wysiwyg editor?

在所见即所得的文本编辑器源代码视图中,我有这个简单的html:

<span style="font-family: Moul;" {%if  loop.first=='first'%} first="" {%endif%}>Hello Text</span>

但是,当我从源视图切换到可视视图时,wysiwyg将我的html代码更改为:

<span style="font-family: Moul;" {%if="" loop.first="='first'%}" {%endif%}="">Hello Text</span>

但是,我想保留我的html,而不是通过文本编辑器更改。

 $('#summernote').summernote({ height: 300 }); 
 body { padding: 40px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css"> <script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.5.0/summernote.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.5.0/summernote.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.5.0/summernote-bs3.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.min.css"> <textarea name="summernote" id="summernote" cols="30" rows="10"> </textarea> 

编辑:

实际上,wysiwyg将单个html属性转换为附加“=”和双引号" "符号。 我在wysiwyg的源视图中测试了写<input type="checkbox" checked> ,它将被转换属性检查为这样:因为wysiwyg将单个属性检查为无效属性,因此它附加等号“=”和双引号“”输出<input type="checkbox" checked=""> 您可以在上面的代码段中测试它。 因此,我的上面的jinja2语法附加了=" " ,这会在运行时导致语法错误异常。

我试图使用正则表达式来帮助让wysiwyg改变我的html,如下所示:

codeview = $('summernote').summernote('code');
console.log(codeview);
Regx  =  /(\<.*\s*\{\%[^}]*\%\}.*\s*\>)/g;
codeview.replace(Regx,'$1');

但它仍然在代码视图和视觉视图之间切换视图时更改我的html。

如何保持我的html不受wysiwyg summernote编辑器的影响? 谢谢。

我假设你有一些代码检查第first属性?

如果那是CSS,那么如果可能的话你可以改变它以检查是否有first属性:

[first]:not([first='']){ }

如果这是javascript它是:

document.querySelectorAll("[first]:not([first=''])");

想要澄清上述内容的原因是,如果是这种情况,您可以在第first属性中移动您的条件,并希望它将保持不变:

<span style="font-family: Moul;" first="{%if loop.first=='first' %}true{%endif%}">Hello Text</span>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM