Hou*_*run 5 html javascript wysiwyg jinja2 summernote
在所见即所得的文本编辑器源代码视图中,我有这个简单的html:
<span style="font-family: Moul;" {%if loop.first=='first'%} first="" {%endif%}>Hello Text</span>
Run Code Online (Sandbox Code Playgroud)
但是,当我从源视图切换到可视视图时,wysiwyg将我的html代码更改为:
<span style="font-family: Moul;" {%if="" loop.first="='first'%}" {%endif%}="">Hello Text</span>
Run Code Online (Sandbox Code Playgroud)
但是,我想保留我的html,而不是通过文本编辑器更改.
$('#summernote').summernote({
height: 300
});Run Code Online (Sandbox Code Playgroud)
body {
padding: 40px;
}Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)
事实上,wysiwyg将单个html属性转换为附加"="和双引号" ".我测试了<input type="checkbox" checked>在wysiwyg的源视图中写入,它将被转换属性检查为这样:因为wysiwyg将单个属性视为无效属性,因此它附加等号"="并双引号""输出<input type="checkbox" checked="">.您可以在上面的代码段中测试它.因此,这是我的jinja2上面的语法附加,=并" "在运行时导致语法错误异常.
我试图使用正则表达式来帮助让wysiwyg改变我的html,如下所示:
codeview = $('summernote').summernote('code');
console.log(codeview);
Regx = /(\<.*\s*\{\%[^}]*\%\}.*\s*\>)/g;
codeview.replace(Regx,'$1');
Run Code Online (Sandbox Code Playgroud)
但它仍然在代码视图和视觉视图之间切换视图时更改我的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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
437 次 |
| 最近记录: |