通过在tinymce

时间:2016-10-25 07:53:54

标签: javascript html tinymce tinymce-4

目前我使用tinymce的旧版本(2.8),现在我尝试将其升级到最新版本(4)。在这个过程中,我遇到了一些麻烦,主要的是在html查看器中显示<![if !mso]>,隐藏在旧版本中,

我使用这个编辑器作为我的邮件编辑器,所以基本上我将一个响应式html邮件文本加载到编辑器中。但它在整个html查看器中显示<![if !mso]>这段代码,但未将其解释为注释。

enter image description here

我使用过的代码(根据example

tinymce.init({
  selector: 'textarea',
  height: 500,
  theme: 'modern',
  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 imagetools codesample'
  ],
  toolbar1: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
  toolbar2: 'print preview media | forecolor backcolor emoticons | codesample',
  image_advtab: true,
  relative_urls : false
 });

任何人都知道如何从HTML查看器中隐藏此<![if !mso]>代码。请注意,此评论非常重要,因此我不想在加载到编辑器之前将其从html代码中删除。我只需要隐藏它们。

1 个答案:

答案 0 :(得分:3)

这里的核心问题是<![if !mso]>不是有效的HTML标记,因此TinyMCE(作为HTML编辑器)将其视为文本。您可以使用TinyMCE配置中的protect选项教TinyMCE保护编辑器中的某些文本:

https://www.tinymce.com/docs/configure/content-filtering/#protect

例如,你可以这样做:

tinymce.init({
    selector: textarea,
    protect: [
      /\<!\[if !mso\]\>/g,   // Protect <![if !mso]>
      /\<!\[if !vml\]\>/g,   // Protect <![if !vml]>
      /\<!\[endif\]\>/g,     // Protect <![endif]>
      /<\?php[\s\S]*?\?>/g   // Protect <?php ?> code
    ]
});

请注意,MS Office文档会放入大量这些非标准标记标记,以便捕获所有这些标记,您可能需要在protect配置选项中添加其他项目。

相关问题