How to prevent CKEditor from stripping < and > (greater-than/less-than)

我的未来我决定 提交于 2019-12-04 01:26:48

问题


Every time I enter < or > in a CKEditor window, save, and then come back to it, CKEditor replaces them with whatever was typed within the brackets and the accompanying end tag. For example: if I type <configuration details>, CKEditor will assume it is an HTML tag and put <configuration details></configuration details> in the html source, thus stripping it out altogether from the text. Argh!

Any ideas?


回答1:


Yeah, this is a real pain.

The only workaround I've found so far is to use

CKEDITOR.instances.myInst.setData(myData);

This actually handles escaped vs. unescaped html correctly, so your < and > will come out correctly, as less-than and greater-than signs, instead of being interpreted as markup.

I haven't found a way to get this to work with inlined data yet. The setData() workaround is pretty clunky.




回答2:


The best I've come up with is to use a unicode character which is vaguely less-than-sign-ish, or something functionally reminiscent, for instance, a left arrow could indicate redirection.

You'll need to have a scratch page / notepad kind of thing with your characters open, so you can cut and paste (or Find/Replace) as you're working on your life-saving docs.

Here are a few symbols I've gotten to fill in:

⨞ ◀ ◄ ⇦ ⍃ ❮ ⍄ ► ▶ ▷ ❭ ˃

Any of these may or may not work depending on browser, OS and/or application unicode support and (mis)configuration.

Copy and google-search to find unicode/html/long-description (e.g.,'MODIFIER LETTER RIGHT ARROWHEAD' (U+02C3)) for any character, and use that info to find related or matching symbols.

Here are a couple of examples. You'll need a proper browser and 3D glasses to appreciate them fully.

  • This looks all right!

mysql -u root -p xxxxxx ❮​ /usr/share/icinga2/schema.sql

  • Not so much, but it's a good conversation starter:

◄configuration details►◄/configuration details►

  • Maybe even

mysql -u root -p passw*t ◄ nerf_ischemia.sql

But wow, that's hideous. It's still better than having the less-than sign and everything after it being stripped.

There may be a better symbol out there, or even some hack with infixing an image. But that's my quick fix. In any case, the applicability of this solution is going to depend on various factors including tolerance for character-set imprecision as well as the previously-mentioned OS, software, browser weird-unicode-character support.



来源:https://stackoverflow.com/questions/3581139/how-to-prevent-ckeditor-from-stripping-and-greater-than-less-than

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!