简体   繁体   English

tinyMCE删除其中的所有html标签

[英]tinyMCE removes all html tags inside

I am working on laravel project where in i have to make CMS which requires tinyMCE , in tinyMCE while adding contents like uploading images,links,change color of fonts works perfect and gets store the way it should be in database but when i fetch the record from database and put it in tinymce all html tags are removed or stripped and it displays the plain content that is text , I have tried all possible solutions but none of them have given me desired result 我正在laravel项目中工作,其中我必须制作需要tinyMCE的CMS,在tinyMCE中同时添加内容如上载图像,链接,更改字体颜色可以完美工作并获得应在数据库中存储的方式,但是当我获取记录时从数据库中并将其放在tinymce中,所有html标记均已删除或剥离,并且显示纯文本内容,我已经尝试了所有可能的解决方案,但没有一个给我想要的结果

Any Kind of Help would be appreciated !! 任何帮助将不胜感激!

this is my TinyMCE Config file 这是我的TinyMCE Con​​fig文件

var editor_config = {

    selector: "textarea#page_content",
    plugins: [
      " advlist autolink lists link image charmap print preview hr anchor pagebreak",
      "searchreplace wordcount visualblocks visualchars code fullscreen",
      "insertdatetime media nonbreaking save table contextmenu directionality",
      "emoticons template paste textcolor colorpicker textpattern bbcode"
    ],
    toolbar1: `insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify 
    | bullist numlist outdent indent | link image media`,
    toolbar2: 'print preview media | forecolor backcolor emoticons | fontsizeselect',

   style_formats: [
            {title: 'Open Sans', inline: 'span', styles: { 'font-family':'Open Sans'}},
            {title: 'Arial', inline: 'span', styles: { 'font-family':'arial'}},
            {title: 'Book Antiqua', inline: 'span', styles: { 'font-family':'book antiqua'}},
            {title: 'Comic Sans MS', inline: 'span', styles: { 'font-family':'comic sans ms,sans-serif'}},
            {title: 'Courier New', inline: 'span', styles: { 'font-family':'courier new,courier'}},
            {title: 'Georgia', inline: 'span', styles: { 'font-family':'georgia,palatino'}},
            {title: 'Helvetica', inline: 'span', styles: { 'font-family':'helvetica'}},
            {title: 'Impact', inline: 'span', styles: { 'font-family':'impact,chicago'}},
            {title: 'Symbol', inline: 'span', styles: { 'font-family':'symbol'}},
            {title: 'Tahoma', inline: 'span', styles: { 'font-family':'tahoma'}},
            {title: 'Terminal', inline: 'span', styles: { 'font-family':'terminal,monaco'}},
            {title: 'Times New Roman', inline: 'span', styles: { 'font-family':'times new roman,times'}},
            {title: 'Verdana', inline: 'span', styles: { 'font-family':'Verdana'}}
        ],
      valid_elements : 'img[src]',
      entity_encoding: "raw",
        extended_valid_elements : "em[class|name|id]",
        valid_children : "+body[style], +style[type]",
        apply_source_formatting : false,               
        verify_html : false,                           
     file_browser_callback : function(field_name, url, type, win) {
      var x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
      var y = window.innerHeight|| document.documentElement.clientHeight|| document.getElementsByTagName('body')[0].clientHeight;

      var cmsURL = editor_config.path_absolute + 'laravel-filemanager?field_name=' + field_name;
      if (type == 'image') {
        console.log("Hip Hip Hurray");
        cmsURL = cmsURL + "&type=Images";
      } else {
        cmsURL = cmsURL + "&type=Files";
      }

      tinyMCE.activeEditor.windowManager.open({
        file : cmsURL,
        title : 'Filemanager',
        width : x * 0.8,
        height : y * 0.8,
        resizable : "yes",
        close_previous : "no"
      });
    }
  };

  tinymce.init(editor_config);

and in blade html file 并在刀片html文件中

 <textarea name="page_content" class="form-control" id="page_content" >
  {!!$page->page_content!!}
 </textarea>

and if this content is put outside tinymce then it displays exactly the way i want ie the image ,links does not get stripped off !! 如果将这些内容放置在tinymce之外,那么它将按照我想要的方式显示,即图像,链接不会被剥夺!

You are using the option valid_elements which overrides the existing valid elements. 您正在使用valid_elements选项,该选项将覆盖现有的有效元素。 You config makes it so that only img[src] tags are allowed. 您通过配置使其仅允许img[src]标签。 So when saved, all tags that are not img[src] are removed from your content. 因此,保存后,所有不是img[src]标签都将从您的内容中删除。

You should use extend_valid_elements to add more valid elements to the existing object. 您应该使用extend_valid_elements将更多有效元素添加到现有对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM