【问题标题】:With tinymce, the formatting seems to change when I copy content from a <div>使用tinymce,当我从 <div> 复制内容时,格式似乎发生了变化
【发布时间】:2012-04-13 09:39:33
【问题描述】:

如果我从 word doc 中复制 + 粘贴,这很好,并且它会产生足够接近精确的副本。

如果我在 iframe 中的 a 中显示内容(以防止 css 干扰),它的显示方式与在编辑器中完全相同。

如果我这样做:

tinyMCE.execCommand("mceReplaceContent",false, $("#frameBody").contents().find("#txtBody").html());

它将它复制到 tinyMCE 窗口中,但格式有点不同。项目符号点是空心圆而不是常规圆,并且有相当多的额外间距。

知道如何解决这个问题吗?

我正在像这样创建我的 tinyMCE:

tinyMCE.init({
        // General options
        mode : "textareas",
        theme : "advanced",
        plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,iespell,inlinepopups,insertdatetime,searchreplace,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,code,|,insertdate,inserttime,|,forecolor,backcolor",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",

        // Skin options
        skin : "o2k7",
        skin_variant : "silver",
});

<textarea name='FishBody' style='width:919px; height:600px' id='txtFishBody'></textarea>

【问题讨论】:

    标签: javascript jquery css tinymce rte


    【解决方案1】:

    我已经修复了,结果是拉取 html 的方式有问题。

    基本上,当你保存这个 html 时:

    <div>
    Hello
    </div>
    

    你最终得到了

    <div>\r\nHello\r\n<div>
    

    我通过将 \r\n 替换为 &lt;br/&gt; 来反驳这一点,但似乎没有必要 - 额外的 &lt;br&gt; 标记使它感到困惑。我改成用空字符串替换\r\n,所有问题都解决了:)

    【讨论】:

      【解决方案2】:

      与大多数 rte 一样,tinymce 编辑器为其编辑器 iframe 使用标准 css。这就是子弹看起来不同的原因。外观不同的另一个原因可能是清理功能删除了无效的 html 元素和属性(您可能需要仔细查看 tinymce 配置设置valid_elements 和valid_children)。

      【讨论】:

      • 我认为它可能是 CSS 但我不知道,如果我单击一个空心的项目符号点,然后取消选中工具栏上的项目符号点选项,它会恢复为文本。如果我再次单击它,它又会变成一个要点,但这次它是一个实实在在的要点!
      • 在 rte 编辑器中要根据需要显示单词上下文有很多问题。你能告诉我你切换项目符号选项之前和之后的编辑器内容吗?
      • 啊哈,之前是&lt;ul&gt;&lt;ul&gt;&lt;li&gt;....,之后是&lt;ul&gt;&lt;li&gt;...,这就解释了为什么它是空心的,它是嵌套的。但我不知道为什么 - 源标记是 iframe 中没有 CSS 的纯文本区域,源是 &lt;ul&gt;&lt;li&gt;...&lt;/li&gt;&lt;/ul&gt;。我正在做的是在编辑器中输入内容,保存它,将其加载回
        ,然后当我按下按钮时,它会调用复制操作将其放回编辑器中。我实际上是在尝试将输出反馈到编辑器中,尽管它首先是通过数据库进行的。
      • 但 tinymce 和其他编辑器使用标准 css(可以在编辑器 iframe 的头部找到)
      【解决方案3】:

      你可以试试这个选项

      paste_retain_style_properties: all --或“color font-size”任何你想包含的东西

      示例:复制粘贴我的代码,其中有其他选项,以防万一

      tinymce.init({
                  selector: 'textarea',
                  width: "100%",
                  height : "250",
                  encoding: "xml",
                  menubar: false,
                  statusbar: false,
                  color_cols: "5",
                  setup: function (ed) {
                      ed.on('init', function () {
                          this.getDoc().body.style.fontSize = '10pt';
                          this.getDoc().body.style.fontFamily = 'Arial';
                      });
                  },
                  theme: "modern",
                  browser_spellcheck: true,
                  plugins:
                  [
                      "table paste textcolor"
                  ],
                  paste_retain_style_properties: "all",
                  toolbar1: "undo redo | bold italic underline strikethrough | fontsizeselect fontselect | alignleft aligncenter alignright alignjustify",
                  toolbar2: "copy cut paste | bullist numlist outdent indent | forecolor backcolor | searchreplace | table"
              });
      

      参考:https://www.tiny.cloud/docs/plugins/paste/

      【讨论】:

        猜你喜欢
        相关资源
        最近更新 更多
        热门标签