Skip to content

Commit

Permalink
fix ku#25 add option for textonly to avoid title duplication in case …
Browse files Browse the repository at this point in the history
…of textonly + title
  • Loading branch information
timotheecour committed Aug 11, 2018
1 parent 18e7d8d commit 3fafbe7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions extension/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ <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>%text_n%</dt>
<dd>Selected text or page title. All newlines are copied as they are.</dd>
<dt>%text_br%</dt>
Expand Down
8 changes: 8 additions & 0 deletions spec/createlink-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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%", () => {})
Expand Down
10 changes: 6 additions & 4 deletions src/createlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<br />\n')).
replace(/%text_md%/g, text.replace(/[|\\`*_{}\[\]()#+\-.!]/g, '\\$&')).
Expand Down Expand Up @@ -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)
})
}
Expand Down

0 comments on commit 3fafbe7

Please sign in to comment.