找回密码
 快速注册
搜索
查看: 52|回复: 3

HTML粘贴工具导致文字缺失

[复制链接]

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2023-4-30 23:31 |阅读模式
DiscuzX issue
$ \omega =\{0,1,2,3\ldots |\} $,$ \omega -1=\{0,1,2,3\ldots |\omega \} $
只粘贴了第1句
第2句丢了

output.gif

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2023-4-30 23:45
editor.js
  1. case 'pasteword':
  2.           pasteWord($(ctrlid + '_param_1').contentWindow.document.body.innerHTML);
  3.           hideMenu('', 'win');
  4.           break;
  5.         case 'index':
  6.           if (wysiwyg) {
  7.             str = '';
  8.           } else {
  9.             str = '';
  10.           }
  11.           insertText(str, str.length, 0, false, sel);
  12.           hideMenu('', 'win');
  13.           break;
复制代码
以下为pasteWord函数的定义, 若将其中[^ |>]改为[^>]即可解决上述问题
  1. function pasteWord(str) {
  2.   var mstest = /<\w[^>]* class="?[MsoNormal|xl]"?/gi;
  3.   if (mstest.test(str)) {
  4.     str = str.replace(/<!--\[if[\s\S]+?<!\[endif\]-->/gi, '');
  5.     str = str.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, '<$1$3');
  6.     str = str.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, function ($1, $2, $3, $4) {
  7.       var style = '';
  8.       re = new RegExp('(^|[;\\s])color:\\s*([^;]+);?', 'ig');
  9.       match = re.exec($3);
  10.       if (match != null) {
  11.         style += 'color:' + match[2] + ';';
  12.       }
  13.       re = new RegExp('(^|[;\\s])text-indent:\\s*([^;]+);?', 'ig');
  14.       match = re.exec($3);
  15.       if (match != null) {
  16.         style += 'text-indent:' + parseInt(parseInt(match[2]) / 10) + 'em;';
  17.       }
  18.       re = new RegExp('(^|[;\\s])font-size:\\s*([^;]+);?', 'ig');
  19.       match = re.exec($3);
  20.       if (match != null) {
  21.         style += 'font-size:' + match[2] + ';';
  22.       }
  23.       if (style) {
  24.         style = ' style="' + style + '"';
  25.       }
  26.       return '<' + $2 + style + $4;
  27.     });
  28.     str = str.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, '<$1$3');
  29.     str = str.replace(/<\\?\?xml[^>]*>/gi, '');
  30.     str = str.replace(/<\/?\w+:[^>]*>/gi, '');
  31.     str = str.replace(/&nbsp;/, ' ');
  32.     var re = new RegExp('(<P)([^>]*>.*?)(</P>)', 'ig');
  33.     str = str.replace(re, '<div$2</div>');
  34.     if (!wysiwyg) {
  35.       str = html2bbcode(str);
  36.     }
  37.     insertText(str, str.length, 0);
  38.   }
  39. }
复制代码

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2023-4-30 23:52
在1#例子中
  1. pasteWord('<head></head><body style="width: 550px;" contenteditable="true"><span class="mwe-math-fallback-source-inline tex" dir="ltr">$ \\omega =\\{0,1,2,3\\ldots |\\} $</span>,<span class="mwe-math-fallback-source-inline tex" dir="ltr">$ \\omega -1=\\{0,1,2,3\\ldots |\\omega \\} $</span></body>')
复制代码

只粘贴了第1句. 原因为: pasteWord对于第1对引号只把前引号去掉, 导致html2bbcode在匹配引号时把第一个span也匹配进去了
  1. html2bbcode('<head></head><body contenteditable="true"><span tex" dir="ltr">$ \\omega =\\{0,1,2,3\\ldots |\\} $</span>,<span tex" dir="ltr">$ \\omega -1=\\{0,1,2,3\\ldots |\\omega \\} $</span></body>' )
  2. Output:
  3. "$ \\omega -1=\\{0,1,2,3\\ldots |\\omega \\} $"
复制代码

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2023-5-14 03:12

🆙

希望这个问题得到解决

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 15:29

Powered by Discuz!

× 快速回复 返回顶部 返回列表