šŸ“„ Copy Post Component

:discourse2: Summary Copy post shows a button in the post control of each post which copies the entire contents of the post to the userā€™s clipboard.
:eyeglasses: Preview Preview on Discourse Theme Creator
:hammer_and_wrench: Repository Link https://github.com/discourse/discourse-copy-post
:open_book: New to Discourse Themes? Beginnerā€™s guide to using Discourse Themes

Install this theme component

Settings

Name Description
copy_type Select the type of copied text you would like saved to the clipboard (Markdown or HTML).
copy_button_allowed_groups Select the groups that are allowed to use the copy button. By default, all users in the Trust Level 1 group will see it.
Translation Default
title Copy the contents of this post

Screenshots

The image shows a discussion thread on a forum with various responses discussing the most inspirational movie they have ever seen, including comments on Trees and Albania. (Captioned by AI)


:discourse2: Hosted by us? Theme components are available to use on our Standard, Business, and Enterprise plans.

Last edited by @keegan 2025-01-13T20:29:03Z

Check documentPerform check on document:
24 Likes

Great theme component! Thanks

2 Likes

What happens to formatting and media?

2 Likes

@Zup

May need to make some improvements in this area but currently:

  • media is not copied
  • formatting will be gone (i.e. plain text only) however, line breaks from <p> tags will be present.
2 Likes

Hope this can be updated to include media and formatting when pasted in Discourse.

2 Likes

@Zup

Yes, definitely something Iā€™ll be looking to improve in the future.

However, in the meantime, Iā€™ve added a setting to copy the raw HTML content instead. If you set this to true, the copy button will copy the raw HTML of the post instead of the plain text. This way you should have the formatting and media.

4 Likes

Super! :clap:

Maybe a second button, Duplicate, (in the moderator gear icon area?) to automatically copy the entire contents of the post into a new topic with "DUPLICATE: " appended to the beginning of the title?

Anyway, very handy as is, thanks!

3 Likes

Maybe make the button do a request to /raw/topic_id/post_number so you can copy the real post content? This way it will act like the very useful Reddit Enhancement Suite ā€œSourceā€ button.

6 Likes

Similar component already exists: Raw Post Button.

Adding a copy button to the modal of that component would combine both approaches, what do you think @keegan @Johani?

4 Likes

@md-misko Yup I think thatā€™s a great idea. Since I created a widget for the copy button, I believe it can be quite simply copied over to be used in the modal.

3 Likes

Is there any trick to show the button to logged in users only?

1 Like

@Jagster

There is now! :smiley: Iā€™ve added a setting to apply a minimum trust level to show the widget. Configuring it to 0 will make it so only logged in users can see the button.

3 Likes

Why canā€™t we put two thumbs up when it is earned :wink:

2 Likes

:+1: :+1:

Now @keegan has them. :smiley:

1 Like

This wasnā€™t working on a new install.
The min_trust_level wasnā€™t selectable in Admin.
edit: component was functioning but wasnā€™t displaying correctly in Admin

I forked the repo and got it working but I set min_trust_level as an integer
So (5) = ā€˜disabledā€™ (0-4) as expected. So a small rewrite.

I havenā€™t done a PR ā€¦ as itā€™s a simplification ā€¦ perhaps someone else can confirm the component isnā€™t working?

2 Likes

Hey @geoff777 Iā€™ve tested this on a new install and it seems to be working correctly for me.
Also if I do apply those changes, the issue with using setting the min_trust_level as an integer in the settings.yml file is that the 0 value isnā€™t appearing in the dropdown.

2 Likes

Any of values, except disabled, isnā€™t appearing in the box when selected. AFAIK any of values is in use, though.

4 Likes

Ah sorry, my mistake, I thought you meant you changed the strings in the enum to integers, but you meant you used the integer type instead. Yes, that seems like a better approach. Iā€™ve updated the theme component to support that. Hopefully this should fix any of the issues.

3 Likes

This is a great TC! In our use case we want our authors to copy full posts and paste them into an external editor of a course website. It would be great if you could copy the whole post including media in HTML or just rich text format.

1 Like

Just a heads up to those who were previously using this. Iā€™ve now moved this from being my personal project to now being an official Theme component :tada:. With that, Iā€™ve done a few changes to modernize the component so it works correctly on the latest Discourse version.

Iā€™ve also updated the settings. Instead of a trust level only setting, you can now select any groups you want to be allowed to use the copy button. Additionally, Iā€™ve allowed for a copy_type setting so you can choose whether the copied text is the postā€™s HTML markup or the raw Markdown.

5 Likes