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

时间:2018-03-20 04:10:04

标签: javascript html jinja2 wysiwyg summernote

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

public String[] parseTransfer(String cubacelMessage) {

        String[] data = new String[2];

        Pattern pattern = Pattern.compile("Usted ha recibido (\\d+\\.\\d+) CUC del numero (\\d+).*", Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(cubacelMessage);

        matcher.find();

        data[1] = matcher.group(1);
        data[2] = matcher.group(2);

        return data;
    }

然而,当我从源视图切换到视觉视图时,wysiwyg将我的html代码更改为:

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

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

<span style="font-family: Moul;" {%if="" loop.first="='first'%}" {%endif%}="">Hello Text</span>
$('#summernote').summernote({
  height: 300
});
body {
  padding: 40px;
}

编辑:

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

我尝试使用正则表达式来帮助让wysiwyg改变我的html:

" "

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

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

1 个答案:

答案 0 :(得分:0)

我假设你有一些代码检查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>