复制粘贴到支持彩色文本的地方时,语法高亮不会被复制

没错!我也遇到了同样的行为。

严格来说,这并非一个缺陷。Firefox 只是完全按照请求复制了 HTML:

<meta http-equiv="content-type" content="text/html; charset=utf-8">
<p dir="auto">当我从 Discourse 复制以下内容到我的邮件客户端时:</p>
<pre data-code-wrap="diff" dir="auto" class="codeblock-buttons">
		<div class="codeblock-button-wrapper" style="right: 0px;"></div>
		<code class="lang-diff hljs language-diff" data-highlighted="yes">
			<span class="hljs-meta">@@ -1,11 +1,11 @@</span>
			<span class="hljs-deletion">-Young volunteer award – celebrating young volunteers, aged 16-24, who go the extra mile in their local communities, demonstrating our values and the importance of connection and action.</span>
			<span class="hljs-addition">+The Young Volunteer Award celebrates young volunteers, aged 16–24, who go the extra mile in their local communities, demonstrating our values and the importance of connection and action.</span>
		</code>
	</pre>

粘贴后产生的差异源于 Chromium 将样式内联,而 Firefox 则没有。将其简化为单行可以突显[1] 正在发生的情况:

<span
  class="hljs-deletion">
-Young volunteer award – celebrating young volunteers, aged 16-24, who go the extra mile in their local communities, demonstrating our values and the importance of connection and action.
</span>
<span
  class="hljs-deletion"
  style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 224, 224); color: rgb(192, 45, 46);">
-Young volunteer award – celebrating young volunteers, aged 16-24, who go the extra mile in their local communities, demonstrating our values and the importance of connection and action.
</span>

(已添加换行符)

Chromium 会将来自 class="hljs-deletion" 的内联 CSS style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 224, 224); color: rgb(192, 45, 46);" 内联到 span 标签中,因为它粘贴到的目标可能没有该样式。


  1. 哈哈 ↩︎

1 个赞