Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.4.1",
"version": "0.4.4",
"manifest_version": 2,
"background": {
"scripts": ["js/background.js"],
Expand Down
4 changes: 4 additions & 0 deletions extension/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ <h2>Variables</h2>
<dl id="variables">
<dt>%text%</dt>
<dd>Selected text or page title. All newlines are converted to " ".</dd>
<dt>%textonly%</dt>
<dd>Selected text. All newlines are converted to " ".</dd>
<dt>%onnonemptyselection%</dt>
<dd>on nonempty selection, inserts a hardcoded string.</dd>
<dt>%text_n%</dt>
<dd>Selected text or page title. All newlines are copied as they are.</dd>
<dt>%text_br%</dt>
Expand Down
16 changes: 12 additions & 4 deletions spec/createlink-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})
Expand Down
13 changes: 9 additions & 4 deletions src/createlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<br />\n')).
replace(/%text_md%/g, text.replace(/[|\\`*_{}\[\]()#+\-.!]/g, '\\$&')).
Expand Down Expand Up @@ -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)
})
}
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down