From 3fafbe7e9570b02880c3f8f5b04837593e6eee5f Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Sat, 11 Aug 2018 13:14:29 -0700 Subject: [PATCH 1/5] fix #25 add option for textonly to avoid title duplication in case of textonly + title --- extension/options.html | 2 ++ spec/createlink-spec.js | 8 ++++++++ src/createlink.js | 10 ++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/extension/options.html b/extension/options.html index ec04f1e..ec686b2 100644 --- a/extension/options.html +++ b/extension/options.html @@ -62,6 +62,8 @@

Variables

%text%
Selected text or page title. All newlines are converted to " ".
+
%textonly%
+
Selected text. All newlines are converted to " ".
%text_n%
Selected text or page title. All newlines are copied as they are.
%text_br%
diff --git a/spec/createlink-spec.js b/spec/createlink-spec.js index 0444d3f..f3ecbe3 100644 --- a/spec/createlink-spec.js +++ b/spec/createlink-spec.js @@ -77,6 +77,14 @@ describe("CreateLink", () => { var t = createLink.formatLinkText({format: "%text%"}, url, "ONE\nTWO", title, []) expect(t).toEqual("ONE TWO") }) + it("replaces %textonly%", () => { + var t = createLink.formatLinkText({format: "%textonly%"}, url, "ONE\nTWO", title, []) + expect(t).toEqual("ONE TWO") + }) + it("replaces %textonly%", () => { + var t = createLink.formatLinkText({format: "%textonly%"}, url, undefined, title, []) + expect(t).toEqual(title) + }) xit("replaces %text_n%", () => {}) xit("replaces %text_br%", () => {}) xit("replaces %text_md%", () => {}) diff --git a/src/createlink.js b/src/createlink.js index 1f94b41..b9b2595 100644 --- a/src/createlink.js +++ b/src/createlink.js @@ -19,12 +19,13 @@ class CreateLink { return Promise.resolve(data); } - formatLinkText(def, url, text, title, inputs) { + formatLinkText(def, url, text, textonly, title, inputs) { text = text || '' var data = def.format. replace(/%url%/g, url). replace(/%text%/g, text.replace(/\n/g, ' ')). + replace(/%textonly%/g, textonly.replace(/\n/g, ' ')). replace(/%text_n%/g, text). replace(/%text_br%/g, text.replace(/\n/g, '
\n')). replace(/%text_md%/g, text.replace(/[|\\`*_{}\[\]()#+\-.!]/g, '\\$&')). @@ -60,15 +61,16 @@ class CreateLink { url = info.linkUrl || info.pageUrl || tab.url; } var text = info.selectionText || tab.title; + var textonly = info.selectionText; var title = tab.title; var def = this.formats[formatId] - return this.formatString(tab.id, def, url, text, title) + return this.formatString(tab.id, def, url, text, textonly, title) } - formatString(tabId, def, url, text, title) { + formatString(tabId, def, url, text, textonly, title) { return this.getInputs(def, tabId).then( (inputs) => { - const linkText = this.formatLinkText(def, url, text, title, inputs) + const linkText = this.formatLinkText(def, url, text, textonly, title, inputs) return this.applyFilter(tabId, def, linkText) }) } From a78abde6bed2273717a30037d111f712d5c04e06 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 14 Aug 2018 21:55:10 -0700 Subject: [PATCH 2/5] fixup --- spec/createlink-spec.js | 18 +++++++++--------- src/createlink.js | 1 + webpack.config.js | 3 ++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/spec/createlink-spec.js b/spec/createlink-spec.js index f3ecbe3..e9144a7 100644 --- a/spec/createlink-spec.js +++ b/spec/createlink-spec.js @@ -70,32 +70,32 @@ describe("CreateLink", () => { var title = 'pageTitle' var url = 'http://example.com/' it("replaces %url%", () => { - var t = createLink.formatLinkText({format: "%url%"}, url, undefined, title, []) + var t = createLink.formatLinkText({format: "%url%"}, url, undefined, undefined, title, []) expect(t).toEqual(url) }) it("replaces %text%", () => { - var t = createLink.formatLinkText({format: "%text%"}, url, "ONE\nTWO", title, []) + var t = createLink.formatLinkText({format: "%text%"}, url, "ONE\nTWO", "ONE\nTWO", title, []) expect(t).toEqual("ONE TWO") }) - it("replaces %textonly%", () => { - var t = createLink.formatLinkText({format: "%textonly%"}, url, "ONE\nTWO", title, []) + it("replaces %textonly% with selection", () => { + var t = createLink.formatLinkText({format: "%textonly%"}, url, "ONE\nTWO", "ONE\nTWO", title, []) expect(t).toEqual("ONE TWO") }) - it("replaces %textonly%", () => { - var t = createLink.formatLinkText({format: "%textonly%"}, url, undefined, title, []) - expect(t).toEqual(title) + it("replaces %textonly% no selection", () => { + var t = createLink.formatLinkText({format: "%textonly%"}, url, undefined, undefined, title, []) + expect(t).toEqual('') }) xit("replaces %text_n%", () => {}) xit("replaces %text_br%", () => {}) xit("replaces %text_md%", () => {}) it("replaces %title%", () => { - var t = createLink.formatLinkText({format: "%title%"}, url, undefined, title, []) + var t = createLink.formatLinkText({format: "%title%"}, url, undefined, undefined, title, []) expect(t).toEqual(title) }) xit("replaces %newline%", () => {}) xit("replaces %htmlEscapedText%", () => {}) it("replaces \t\r\n", () => { - var t = createLink.formatLinkText({format: "\\t\\r\\n"}, url, undefined, title, []) + var t = createLink.formatLinkText({format: "\\t\\r\\n"}, url, undefined, undefined, title, []) expect(t).toEqual("\t\r\n") }) }) diff --git a/src/createlink.js b/src/createlink.js index b9b2595..c04706d 100644 --- a/src/createlink.js +++ b/src/createlink.js @@ -21,6 +21,7 @@ class CreateLink { formatLinkText(def, url, text, textonly, title, inputs) { text = text || '' + textonly = textonly || '' var data = def.format. replace(/%url%/g, url). diff --git a/webpack.config.js b/webpack.config.js index c8c3d08..9a149c9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -10,7 +10,8 @@ module.exports = { //devtool: 'source-map', cache: true, output: { - path: `extension/js`, + // https://stackoverflow.com/questions/42940050/configuration-output-path-the-provided-value-public-is-not-an-absolute-path + path: __dirname + "/extension/js", publicPath: '/', filename: "[name].js" }, From f9e8de624f4b958c4d2ba5208bba5a0b5091b7d4 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 14 Aug 2018 22:05:44 -0700 Subject: [PATCH 3/5] udpated tag --- extension/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/manifest.json b/extension/manifest.json index fc11a6a..0971583 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,5 +1,5 @@ { - "version": "0.4.1", + "version": "0.4.2", "manifest_version": 2, "background": { "scripts": ["js/background.js"], From 1dfc82f6dbc76ccae428aa89fd2c0ab2c7adde20 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 14 Aug 2018 22:23:44 -0700 Subject: [PATCH 4/5] onnonemptyselection --- extension/manifest.json | 2 +- extension/options.html | 2 ++ src/createlink.js | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/extension/manifest.json b/extension/manifest.json index 0971583..eb0ea89 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,5 +1,5 @@ { - "version": "0.4.2", + "version": "0.4.3", "manifest_version": 2, "background": { "scripts": ["js/background.js"], diff --git a/extension/options.html b/extension/options.html index ec686b2..623c814 100644 --- a/extension/options.html +++ b/extension/options.html @@ -64,6 +64,8 @@

Variables

Selected text or page title. All newlines are converted to " ".
%textonly%
Selected text. All newlines are converted to " ".
+
%onnonemptyselection%
+
on nonempty selection, inserts a hardcoded string.
%text_n%
Selected text or page title. All newlines are copied as they are.
%text_br%
diff --git a/src/createlink.js b/src/createlink.js index c04706d..b618059 100644 --- a/src/createlink.js +++ b/src/createlink.js @@ -27,6 +27,8 @@ class CreateLink { replace(/%url%/g, url). replace(/%text%/g, text.replace(/\n/g, ' ')). replace(/%textonly%/g, textonly.replace(/\n/g, ' ')). + // TODO: allow customizing this, eg using regex replace + replace(/%onnonemptyselection%/g, textonly == "" ? " TITLE: " : ""). replace(/%text_n%/g, text). replace(/%text_br%/g, text.replace(/\n/g, '
\n')). replace(/%text_md%/g, text.replace(/[|\\`*_{}\[\]()#+\-.!]/g, '\\$&')). From 55ce6efed7cbb55d40ae95028c099322ed4956c9 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 14 Aug 2018 22:31:21 -0700 Subject: [PATCH 5/5] fixup --- extension/manifest.json | 2 +- src/createlink.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extension/manifest.json b/extension/manifest.json index eb0ea89..e32107b 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,5 +1,5 @@ { - "version": "0.4.3", + "version": "0.4.4", "manifest_version": 2, "background": { "scripts": ["js/background.js"], diff --git a/src/createlink.js b/src/createlink.js index b618059..45cc450 100644 --- a/src/createlink.js +++ b/src/createlink.js @@ -27,8 +27,8 @@ class CreateLink { replace(/%url%/g, url). replace(/%text%/g, text.replace(/\n/g, ' ')). replace(/%textonly%/g, textonly.replace(/\n/g, ' ')). - // TODO: allow customizing this, eg using regex replace - replace(/%onnonemptyselection%/g, textonly == "" ? " TITLE: " : ""). + // TODO: allow customizing instead of hardcoding, eg using regex replace + replace(/%onnonemptyselection%/g, textonly == "" ? "" : " TITLE: "). replace(/%text_n%/g, text). replace(/%text_br%/g, text.replace(/\n/g, '
\n')). replace(/%text_md%/g, text.replace(/[|\\`*_{}\[\]()#+\-.!]/g, '\\$&')).