# 允许将GIF粘贴到作曲家

**URL:** <https://meta.discourse.org/t/allow-pasting-of-gifs-into-composer/218720>\
**Category:** Feature\
**Tags:** completed\
**Created:** [2022年二月18日 19:30 UTC](https://meta.discourse.org/t/allow-pasting-of-gifs-into-composer/218720 "2022-02-18T19:30:51Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2022年二月18日 19:30 UTC](https://meta.discourse.org/t/allow-pasting-of-gifs-into-composer/218720/1 "2022-02-18T19:30:51Z")

</div>

继续讨论 [是否可以将图片粘贴为其源地址？](https://meta.discourse.org/t/is-it-possible-to-paste-images-as-their-source-address/218554)：

如果您在浏览器中右键单击互联网上的 GIF 并选择“复制图像”，您的剪贴板将包含两个元素：

1. GIF 的静态 PNG 图像，类型为 `image/png`
2. 一个 HTML `img` 标签，其中包含 GIF 源，类型为 `text/html`

对于大多数用例，选择剪贴板中的选项 1 并立即在编辑器中上传该图像可以提供更好的用户体验，因此我们始终这样做。但是，对于动画 GIF，我们可能希望颠倒逻辑并粘贴图像源地址，这样动画就不会完全丢失。

复制 Google 图片搜索中的随机 GIF 后，剪贴板中 JS 事件内容的示例：

```html
<img src="https://c.tenor.com/tX_T48A14BwAAAAd/khaby-really.gif" alt="Khaby Really GIF - Khaby Really - Discover &amp;amp; Share GIFs" jsaction="load:XAeZkd;" jsname="HiaYvf" class="n3VNCb" data-noaft="1" style="width: 389px; height: 389px; margin: 0px;">

```

BBPress 编辑器具有此功能，因此我们必须迎头赶上！

---

<div class="post-metadata">

**Author:** ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)\
**Post date:** [2022年二月28日 05:05 UTC](https://meta.discourse.org/t/allow-pasting-of-gifs-into-composer/218720/2 "2022-02-28T05:05:49Z")

</div>

那会好得多。

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2022年三月16日 17:38 UTC](https://meta.discourse.org/t/allow-pasting-of-gifs-into-composer/218720/3 "2022-03-16T17:38:53Z")

</div>

我有一个拉取请求，其中包含一个建议的解决方案：

> <https://github.com/discourse/discourse/pull/16204>
>
> If a user copies a gif from a website into their clipboard and then
> tries to pa…ste it into the Discourse composer, we would only paste a
> static single frame of the original gif. This happens because the
> browser doesn't store the original image in the clipboard, but two
> entries:
> 
> 1. image/png with the frame of the copy moment
> 2. text/html with the markup of the gif img element
> 
> This commit adds an heuristic that detects this and makes us pick the
> clipboard content of text/html instead of the image/png when this
> happens.
> 
> From there our existing HTML paste logic handles and converts the HTML
> img tag into markdown, preserving even the alt text.
> 
> See https://meta.discourse.org/t/-/218720 for context.
> 
> 
> I looked into adding tests, but mocking the event and clipboardData in a faithful way was non-trivial.

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2022年三月17日 18:15 UTC](https://meta.discourse.org/t/allow-pasting-of-gifs-into-composer/218720/4 "2022-03-17T18:15:41Z")

</div>

之前：

 ![image](https://global.discourse-cdn.com/meta/original/3X/8/b/8b16b279fbdf831790435d3b917d15092a4bd52d.png)

之后：  
 ![](https://media1.giphy.com/media/v1.Y2lkPTc5MGI3NjExMmlwbXE0N213ZHo2c2RtbmY2dHlieDV3ZWljNTc4b3JxcDNqc2E4NSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/IVDYYv6Cto6LS/giphy.webp "Star Trek Tantrum GIF - Find & Share on GIPHY")

你能试试吗 @danielabc？

---

<div class="post-metadata">

**Author:** ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)\
**Post date:** [2022年三月19日 10:25 UTC](https://meta.discourse.org/t/allow-pasting-of-gifs-into-composer/218720/5 "2022-03-19T10:25:09Z")

</div>

太好了，你会说葡萄牙语，哈哈  
我在这里有点迷茫，PR 是什么意思？是巴拉那州吗？哈哈

你给我的这个链接是一个插件吗？我需要安装它吗？

谢谢

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [2022年三月19日 10:26 UTC](https://meta.discourse.org/t/allow-pasting-of-gifs-into-composer/218720/6 "2022-03-19T10:26:26Z")

</div>

无需插件，只需更新到最新版本即可。🙂👍

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2022年三月19日 13:49 UTC](https://meta.discourse.org/t/allow-pasting-of-gifs-into-composer/218720/7 "2022-03-19T13:49:59Z")

</div>

正如我们的同事所说，只需更新您的 Discourse。

---

<div class="post-metadata">

**Author:** ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)\
**Post date:** [2022年三月20日 09:13 UTC](https://meta.discourse.org/t/allow-pasting-of-gifs-into-composer/218720/8 "2022-03-20T09:13:24Z")

</div>

真的吗？他们仅仅因为我修改了 Discourse 吗？太棒了 kkk  
PR 是什么意思？它是让他们修复某事的建议吗？我也可以提供建议吗？

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2022年三月21日 20:37 UTC](https://meta.discourse.org/t/allow-pasting-of-gifs-into-composer/218720/9 "2022-03-21T20:37:06Z")

</div>

> [@danielabc](#):
>
> PR 是什么意思？

“更改建议”。当您提交软件代码更改以包含新功能或修复缺陷时。

就我而言，我编写了此功能，并将其作为 PR 提交，由公司其他同事进行评估，最终将其合并到软件中。

---

<div class="post-metadata">

**Author:** ![PaulinaMX](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paulinamx/32/210473_2.png) [@PaulinaMX](https://meta.discourse.org/u/PaulinaMX)\
**Post date:** [2022年三月21日 20:40 UTC](https://meta.discourse.org/t/allow-pasting-of-gifs-into-composer/218720/10 "2022-03-21T20:40:23Z")

</div>

太棒了！❤

[https://c.tenor.com/r-acShkJxuoAAAAd/paola-bracho4.gif(image larger than 10 MB)](https://c.tenor.com/r-acShkJxuoAAAAd/paola-bracho4.gif)

---

<div class="post-metadata">

**Author:** ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)\
**Post date:** [2022年三月23日 07:29 UTC](https://meta.discourse.org/t/allow-pasting-of-gifs-into-composer/218720/11 "2022-03-23T07:29:04Z")

</div>

> [@Falco](#):
>
> 代码的更改，以便它包含一项新功能或修复了某个错误。
> 
> 就我而言，我编写了此功能，并将其作为 PR 提交，由其他同事进行评估

我在这里进行了测试，你们做得太棒了！这次更改极大地提高了论坛的可用性，现在成员甚至可以使用其他成员通过论坛上传的 GIF！效果太棒了！（以前不行，图片会卡住，哈哈）非常感谢！

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [2022年十一月9日 13:31 UTC](https://meta.discourse.org/t/allow-pasting-of-gifs-into-composer/218720/12 "2022-11-09T13:31:48Z")

</div>


