From f1346173db692ea427c98e8c1c9982ea85ea7617 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Mon, 21 Feb 2022 12:25:06 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20FEATURE:=20Ability=20to=20copy=20ra?= =?UTF-8?q?w=20html=20instead?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- about.json | 2 +- javascripts/discourse/widgets/copy-widget.js | 7 ++++++- settings.yml | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/about.json b/about.json index 6754eec..cc0328b 100644 --- a/about.json +++ b/about.json @@ -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": [ diff --git a/javascripts/discourse/widgets/copy-widget.js b/javascripts/discourse/widgets/copy-widget.js index a0fb0ad..f522daa 100644 --- a/javascripts/discourse/widgets/copy-widget.js +++ b/javascripts/discourse/widgets/copy-widget.js @@ -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>/g, '$1\n'); - const postContents = cookedText.replace(/(<([^>]+)>)/gi, ''); + let postContents = cookedText.replace(/(<([^>]+)>)/gi, ''); + + if (settings.copy_raw_html) { + postContents = rawCooked; + } const state = copyButton.innerHTML; diff --git a/settings.yml b/settings.yml index e69de29..1228dca 100644 --- a/settings.yml +++ b/settings.yml @@ -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" \ No newline at end of file