diff --git a/extension/manifest.json b/extension/manifest.json
index fc11a6a..e32107b 100644
--- a/extension/manifest.json
+++ b/extension/manifest.json
@@ -1,5 +1,5 @@
{
- "version": "0.4.1",
+ "version": "0.4.4",
"manifest_version": 2,
"background": {
"scripts": ["js/background.js"],
diff --git a/extension/options.html b/extension/options.html
index ec04f1e..623c814 100644
--- a/extension/options.html
+++ b/extension/options.html
@@ -62,6 +62,10 @@
Variables
- %text%
- 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/spec/createlink-spec.js b/spec/createlink-spec.js
index 0444d3f..e9144a7 100644
--- a/spec/createlink-spec.js
+++ b/spec/createlink-spec.js
@@ -70,24 +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% with selection", () => {
+ var t = createLink.formatLinkText({format: "%textonly%"}, url, "ONE\nTWO", "ONE\nTWO", title, [])
+ expect(t).toEqual("ONE TWO")
+ })
+ 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 1f94b41..45cc450 100644
--- a/src/createlink.js
+++ b/src/createlink.js
@@ -19,12 +19,16 @@ class CreateLink {
return Promise.resolve(data);
}
- formatLinkText(def, url, text, title, inputs) {
+ formatLinkText(def, url, text, textonly, title, inputs) {
text = text || ''
+ textonly = textonly || ''
var data = def.format.
replace(/%url%/g, url).
replace(/%text%/g, text.replace(/\n/g, ' ')).
+ replace(/%textonly%/g, textonly.replace(/\n/g, ' ')).
+ // 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, '\\$&')).
@@ -60,15 +64,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)
})
}
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"
},