Input code in TinyMCE

2019-07-23 01:48发布

I'm using TinyMCE on my blog and it seems to be removing the code I'm trying to paste.

I want to add this:

<Files somefile.png>
    DefaultType application/x-httpd-php
</Files>

(it's a .htaccess directive)

This gets saved ok (as &lt; and &gt; in the html), but when I reopen my form for editing, it gets transformed as :

DefaultType application/x-httpd-php

Edit : I'm using TinyMCE in a Symfony form, using sfFormExtraPlugin.

Edit 2 : I tried verify_html: false .... now my code gets transformed as :

<p><files exec="" jpg=""><br /> DefaultType application/x-httpd-php<br /></files></p>

Edit 3: My tinyMCE config is :

  tinyMCE.init({
    mode:                              "exact",
    elements:                          "content_contents",
    theme:                             "advanced",
    width:                             "500px",
    height:                            "400px",
    theme_advanced_toolbar_location:   "top",
    theme_advanced_toolbar_align:      "left",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_resizing:           true
    ,

    language : "fr",
        convert_urls : false,
        verify_html : false

  });

6条回答
啃猪蹄的小仙女
2楼-- · 2019-07-23 02:02

That is because the invalid HTML gets removed (the tinymce cleanup functionality).

A workaround could be to initialize tinymce using the cleanup paramter:

cleanup: false,

I suggest you have a closer look at the tinymce initialization parameters

and

查看更多
叼着烟拽天下
3楼-- · 2019-07-23 02:03

replace your < and >

< becomes: &lt;
> becomes: &gt;
查看更多
我只想做你的唯一
4楼-- · 2019-07-23 02:05

I responded to this on the TinyMCE MoxieCode forums topic that was also opened by @Manu however I wanted to update this topic with my thoughts as well.

If I understand @Manu correctly, the problem is that the HTML source, while saving with &lt and &gt correctly is being interpreted as < and > when reloaded into TinyMCE.

If this is the case, then I believe the problem is that the Symphony plugin isn't encoding the HTML content prior to populating the TextArea that TinyMCE replaces. In other words, it leaves &lt when it should be loading &lt; so tinyMCE receives &lt

查看更多
太酷不给撩
5楼-- · 2019-07-23 02:07

What are you doing to the input when putting it back in to TinyMCE? If you're converting it to HTML or anything TinyMCE will clean it up as it's invalid HTML.

As a work around/experiment you could add File in the custom_elements option in your init.

Update As you are accepting all sorts of code, you will probably have to turn off clean up altogether. Put cleanup: false in the config. If I were you I would implement your own custom formatting (like Stack/overflow does) and generate bold, underline, links etc formatting because it will give you a lot more control over the HTML generation, ie you could just print out everything exactly how it is (with escaping), and then turn the pre-defined symbols to <strong> tags, or what ever. This is be far the easiest way of generating safe, accurate HTML output, and in your case, probably the only way.

You would not want to use TinyMCE is this case...

查看更多
倾城 Initia
6楼-- · 2019-07-23 02:15

Try including
extended_valid_elements : "Files[]",
In your config. It's used to unlock certain html tags like iframe. In the brackets you usually put the allowed options for the tag (like [src|alt|id]) so I'm not sure what to put there for your example ...

查看更多
来,给爷笑一个
7楼-- · 2019-07-23 02:21

the correct answer to your problem, tested by me and 100% working is to wrap your variable into htmlspecialchars in php like this example:

htmlspecialchars($myText)
查看更多
登录 后发表回答