I can successfully save the characters < and >.
I do this with these options:
entities : """
cle开发者_运维百科anup : false
verify_html : false
So far no problems.
However, whenever I put anything between that text it gets converted into a tag:
<xxx>
converts to
<xxx></xxx>
How do I stop that?I am trying to enter sample HTML into TinyMCE so I can document some XML. There must be a standard way of doing this I imagine.
It sounds very much like you're not encoding the < and > characters correctly. TinyMCE is a HTML editor and the content it's editing gets parsed by the browser, so having unescaped < and > in the content is likely to produce unexpected results based on the browser's handling of malformed HTML.
Be aware that depending on how you load the HTML to edit, the browser may decode entities once before it gets to TinyMCE in which case you'd have to doubly encode the entity to get it loaded safely.
Regards,
Adrian Sutton
http://tinymce.ephox.com
I basically elaborate the answer of ajsutton, which was the starting point to solve the problem for my needs.
You have to escape the < and > twice, because the browser unescapes the data got from the server once, before handing it over to TinyMCE.
Assume you want to open a TinyMCE WYSIWYG textarray showing "The HTML tag for boldface is <B>. A non-existent HTML tag is <NONSENSE>."
Assume the server sends the following page source:
<script language="javascript" type="text/javascript">
tinyMCE.init({
selector : "textarea.myMCE",
...
});
</script>
...
<TEXTAREA NAME="TEST" class="myMCE" ROWS="25" COLS="80">
The HTML tag for boldface is <CODE><B>.</CODE>
A nonexistent HTML tag is <CODE><NONSENSE>.</CODE>
</TEXTAREA>
This will fail. The browser (firefox in my case) decodes the source once before sending it to TinyMCE; you can see this by removing the "class=myMCE" tag, so you get a plain html textarray with the following content:
The HTML tag for boldface is <CODE><B>.</CODE>
A nonexistent HTML tag is <CODE><NONSENSE>.</CODE>
If TinyMCE (4 in my case) gets this data, and you look at "tools":"Source code" you can see:
The HTML tag for boldface is <CODE><B>.</CODE>
A nonexistent HTML tag is <CODE>.</CODE>
TinyMCE has suppressed the invalid html tag "<NONSENSE>". The rendered Text in THE TinyMCE textarray will look like:
The HTML tag for boldface is . A nonexistent HTML tag is .
Please note that the first "." is bold now!
The proper html source the server should send is:
<TEXTAREA NAME="TEST" class="myMCE" ROWS="25" COLS="80">
The HTML tag for boldface is <CODE>&lt;B&gt;.</CODE>
A nonexistent HTML tag is <CODE>&lt;NONSENSE&gt;.</CODE>
</TEXTAREA>
i.e., all "&" are replaced by "&" in the content of the textarray.
How you can achieve that depends on the programming language you use for your cgi scripts. In php, str_replace("&", "&", $textarrea_contents) should work.
Add this:
entity_encoding : "raw"
To TinyMCE init configuration:
tinyMCE.init({
// ...
entity_encoding : "raw"
});
Reference:
entity_encoding
configuration on TinyMCE: https://www.tiny.cloud/docs-3x/reference/Configuration3x/Configuration3x@entity_encoding/
Try it like this:
In the "Source Code" modal window, paste and save.
精彩评论