Forgot password?
 Register account
View 337|Reply 7

粘贴HTML

[Copy link]

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

hbghlyj Posted 2022-9-3 06:31 |Read mode
How to paste rich text from clipboard to HTML textarea element?
  1. document.addEventListener('paste',function(e){e.preventDefault();document.body.innerHTML=e.clipboardData.getData('text/html')})
Copy the Code
建议论坛编辑器添加粘贴HTML, 从别的网页直接粘贴.

682

Threads

110K

Posts

910K

Credits

Credits
90973
QQ

Show all posts

kuing Posted 2022-9-3 16:01
建议论坛编辑器添加粘贴HTML, 从别的网页直接粘贴.
懒得搞。
论坛上除了你,没人有这种需求。
如果你需要,请自己想办法,比如在油猴写段代码,应该很容易实现。

PS、我试了一下,粘贴出来的元素的 style 往往一长串样式,代码很长,也不咋嘀,我估计稍往长一点的内容粘贴到这里就会超过字数限制。

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

 Author| hbghlyj Posted 2022-9-3 16:09
kuing 发表于 2022-9-3 09:01
懒得搞。
论坛上除了你,没人有这种需求。
如果你需要,请自己想办法,比如在油猴写段代码,应该很容易实 ...
话说DiscuzX编辑器的粘贴RTF的工具应该也是基于这个API吧
我们可以研究一下
Screenshot 2022-09-02 at 02-02-12 mspace - MathML MDN.png

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

 Author| hbghlyj Posted 2022-9-11 06:09
hbghlyj 发表于 2022-9-3 09:09
话说DiscuzX编辑器的粘贴RTF的工具应该也是基于这个API吧
DiscuzX编辑器的粘贴RTF的工具就是粘贴HTML然后将用于Office内部而非HTML的(主要是 mso- 开头的)样式过滤掉
On dropping text/html content to MS Word document the mso-element is not recognized

这篇文章: 在线Html编辑器粘贴过滤技术详解(一) 分析了 TinyMCE 的粘贴RTF工具的实现

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

 Author| hbghlyj Posted 2022-9-11 06:13
kuing 发表于 2022-9-3 09:01
粘贴出来的元素的 style 往往一长串样式
这个应该是取决于原网页是否带有很多 inline 的 style 属性, 不会因为粘贴而增加样式, 从我这边来看.

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

 Author| hbghlyj Posted 2022-9-15 18:18
Last edited by hbghlyj 2022-9-18 11:48一个可编辑的<div>可以粘贴HTML:
比如
你可以尝试在这里粘贴HTML.

你可以把红色的字粘贴到此处.
你可以把红色的字粘贴(或选中后拖拽)到上面去

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

 Author| hbghlyj Posted 2022-9-15 18:20
效果: Screenshot 2022-09-15 at 00-58-23 exp(1_x) - Google Search.png

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

 Author| hbghlyj Posted 2022-9-18 18:39
Luckily Word includes an option that allows you to save a filtered HTML file. A filter HTML file will not contain any of this useless Microsoft Office specific data. Under “Save As” you want to select the “Web Page, Filtered” option as shown below.
filtered-html[1].png
This removes all unnecessary cruft from Word documents saved as HTML.
zoompf.com/blog/2010/01/cruft-inside-microsoft-word-html-files/

C# clean Word's nasty HTML
CKEditor has a nice utility that imports text from MS Word. It’s also really nice about creating XHTML.
HTMLtidy

Mobile version|Discuz Math Forum

2025-6-5 01:21 GMT+8

Powered by Discuz!

× Quick Reply To Top Edit