Skip to content

Commit

Permalink
✨ FEATURE: Ability to copy raw html instead
Browse files Browse the repository at this point in the history
  • Loading branch information
keegangeorge committed Feb 21, 2022
1 parent 3df1604 commit f134617
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion about.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"component": true,
"authors": "Keegan George",
"theme_version": "0.1",
"about_url": null,
"about_url": "https://meta.discourse.org/t/copy-post-component/218883",
"license_url": null,
"modifiers": {
"svg_icons": [
Expand Down
7 changes: 6 additions & 1 deletion javascripts/discourse/widgets/copy-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ createWidget('copy-widget', {

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');
const postContents = cookedText.replace(/(<([^>]+)>)/gi, '');
let postContents = cookedText.replace(/(<([^>]+)>)/gi, '');

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

const state = copyButton.innerHTML;

Expand Down
5 changes: 5 additions & 0 deletions settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
copy_raw_html:
type: bool
default: false
description:
"If selected the copied contents will be raw HTML instead of the stripped down plain text"

0 comments on commit f134617

Please sign in to comment.