In wysiwyg text editor source view, I have this simple html:
<span style="font-family: Moul;" {%if loop.first=='first'%} first="" {%endif%}>Hello Text</span>
However, when I switch from source view to visual view, wysiwyg change my html code to this:
<span style="font-family: Moul;" {%if="" loop.first="='first'%}" {%endif%}="">Hello Text</span>
However, I would like to keep my html as it was without changing by text editor.
$('#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>
Edited:
In fact, wysiwyg converted single html attribute to append with "=" and double quotes " "
sign. I tested write <input type="checkbox" checked>
in source view of wysiwyg, it will be converted attribute checked to like this: since wysiwyg treated single attribute checked as an invalid attribute, therefore it append equal sign "=" and double quote "" to it outputting <input type="checkbox" checked="">
. You can test it in code snippet above. This is,therefore, my jinja2
syntax above was appended with =
and " "
which causes an syntax error exception during run time.
I tried to used regular expression to help to keep wysiwyg from changing my html like this:
codeview = $('summernote').summernote('code');
console.log(codeview);
Regx = /(\<.*\s*\{\%[^}]*\%\}.*\s*\>)/g;
codeview.replace(Regx,'$1');
But it still change my html during switching view between code view and visual view.
How can I do to keep my html unchanged from wysiwyg summernote editor? Thanks.
{%if loop.first=='first'%}
. EJS? – Girthjinja2
code. I used to checked condition to set attribute to an html element.In fact, wysiwyg converted single html attribute to append with "=" sign. I tested write<input type="checkbox" checked>
in source view of wysiwyg, it will be converted attributechecked
to like this:<input type="checkbox" checked="">
since wysiwyg treated single attributechecked
as an invalid attribute, therefore it append equal sign "=" and double quote "" to it. Therefore, myjinja2
syntax above was appended with = and " " which causes ansyntax error
exception during runtime. – Dday