tinyMCE删除里面的所有html标签

时间:2017-07-13 05:53:51

标签: javascript php jquery laravel tinymce

我正在开发laravel项目,我必须在这里完成 在添加内容时,在tinyMCE中需要tinyMCE的CMS 喜欢上传图片,链接,改变字体的颜色是完美的 并获取存储它应该在数据库中的方式,但当我获取 从数据库记录并将其放入tinymce中删除所有html标签 或剥离,它显示纯文本内容, 我已经尝试了所有可能的解决方案,但没有一个给我我想要的 结果

任何帮助都将不胜感激!!

这是我的TinyMCE配置文件

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);

并在blade html文件中

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

如果此内容放在tinymce之外,则会显示 正是我想要的方式,即图像,链接不会被剥离!

1 个答案:

答案 0 :(得分:0)

您使用的选项valid_elements会覆盖现有的有效元素。您配置使其仅允许img[src]个标记。因此,保存后,所有非img[src]的代码都会从您的内容中删除。

您应该使用extend_valid_elements向现有对象添加更多有效元素。