使用复制图标复制内容

您好,我希望用户能够在需要时通过点击“复制”图标来复制插件通过表单提供给我的数据,而不是直接打印出来。

我注意到 Discourse 为代码块引入了此功能,但它仅在这些块内有效。我该如何在其他地方按我期望的方式使用它?

谢谢,

也许这个 Theme component 是你在找的 📄 Copy Post Component

5 个赞

我想用它来处理 Custom Wizard 插件的数据,也就是说,我想启用复制特定短语的功能。我认为主题组件不提供此功能。但是,我可以通过自定义来实现吗?

你说得对,该组件会复制整个帖子的内容。这似乎确实可以自定义。你能分享一个你期望的视觉示例吗?我从未使用过这个插件,所以我不太确定你希望在哪个步骤或上下文中进行自定义。

2 个赞

当使用 Custom Wizards 插件创建页面时,我想复制插件提供的变量的输出。因此,我们可以将其视为消息内容中随机选择的区域。我可以为要复制的内容分配自定义 CSS 选择器。

https://github.com/keegangeorge/discourse-copy-post/blob/main/javascripts/discourse/widgets/copy-widget.js

  click(attrs) {
    const copyButton = attrs.currentTarget.activeElement;
    const rawCooked = this.attrs.attrs.cooked;
    const cookedText = this.attrs.attrs.cooked.replace(/<p>(.*)<\/p>/g, "$1\n");
    let postContents = cookedText.replace(/<[^>]+>/gi, "");

    if (settings.copy_raw_html) {
      postContents = rawCooked;
    }

const rawCooked = this.attrs.attrs.cooked;

选择器在这里。我想定位 cooked div 中的最后一个 p 标签或倒数第二个 p 标签,而不是整个 cooked。如果可能的话,我想单独定位它们,并将复制图标放在段落旁边。