Skip to content

Commit

Permalink
Merge pull request #45 from 0x6b/link-style-option
Browse files Browse the repository at this point in the history
feat: add option to disable link styling
  • Loading branch information
0x6b authored Oct 14, 2019
2 parents 954aba8 + ce8ac91 commit c4cbdcf
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ async function main() {
options.debug = typeof options.debug === "undefined" ? false : options.debug;
options.mathjax = typeof options.mathjax === "undefined" ? false : options.mathjax;
options.gfm = typeof options.gfm === "undefined" ? false : options.gfm;
options.linkWithoutStyling = typeof options.linkWithoutStyling === "undefined" ? false : options.linkWithoutStyling;
options.img = typeof options.img === "undefined" ? false : options.img;

let text = `[${document.title}](${document.URL})`;
let text = options.linkWithoutStyling
? `${document.title} (${document.URL})`
: `[${document.title}](${document.URL})`;
let selection = getSelectionAsMarkdown(options);

if (selection.output !== "") {
Expand Down
2 changes: 1 addition & 1 deletion src/icons/generate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {
clippy: { path }
} = require("octicons");
} = require("@primer/octicons");
const { writeFileSync } = require("fs");
const { resolve } = require("path");
const { parseString } = require("xml2js");
Expand Down
6 changes: 6 additions & 0 deletions src/lib/turndown-plugin-link-without-styling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function strikethrough(turndownService) {
turndownService.addRule("inlineLink", {
filter: (node, options) => options.linkStyle === "inlined" && node.nodeName === "A" && node.getAttribute("href"),
replacement: (content, node) => `${content} (${node.getAttribute("href")}${node.title ? ` "${node.title}"` : ""})`
});
}
5 changes: 5 additions & 0 deletions src/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import TurndownService from "turndown";
import turndownPluginMathJax from "./turndown-plugin-mathjax";
import turndownPluginGfmStrikethrough from "./turndown-plugin-gfm-strikethrough";
import turndownPluginImg from "./turndown-plugin-img";
import turndownPluginLinkWithoutStyling from "./turndown-plugin-link-without-styling";
import { tables, taskListItems } from "turndown-plugin-gfm";
import * as copy from "clipboard-copy";

Expand All @@ -24,6 +25,10 @@ const getSelectionAsMarkdown = options => {
turndownService.use(turndownPluginImg);
}

if (options.linkWithoutStyling) {
turndownService.use(turndownPluginLinkWithoutStyling)
}

let html = "";
let sel = document.getSelection();

Expand Down
2 changes: 2 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ document.addEventListener("DOMContentLoaded", () => {
document.querySelector("#debug").checked = typeof result.debug === "undefined" ? false : result.debug;
document.querySelector("#mathjax").checked = typeof result.mathjax === "undefined" ? false : result.mathjax;
document.querySelector("#gfm").checked = typeof result.gfm === "undefined" ? false : result.gfm;
document.querySelector("#linkWithoutStyling").checked = typeof result.linkWithoutStyling === "undefined" ? false : result.linkWithoutStyling;
document.querySelector("#img").checked = typeof result.img === "undefined" ? false : result.img;
},
error => console.log(`Error: ${error}`)
Expand All @@ -45,6 +46,7 @@ document.querySelector("form").addEventListener("submit", e => {
debug: document.querySelector("#debug").checked,
mathjax: document.querySelector("#mathjax").checked,
gfm: document.querySelector("#gfm").checked,
linkWithoutStyling: document.querySelector("#linkWithoutStyling").checked,
img: document.querySelector("#img").checked
});
});
4 changes: 3 additions & 1 deletion src/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ <h2>General</h2>
<input type="checkbox" id="gfm">
<label for="gfm">Enable <a href="https://github.github.com/gfm/">GitHub Flavored Markdown</a> (strikethrough,
tables, and taskListItems) support</label><br>
<input type="checkbox" id="linkWithoutStyling">
<label for="linkWithoutStyling">Disable link styling (<code>like this (https://example.com)</code> instead of <code>[like this](https://example.com)</code>)</label><br>
<input type="checkbox" id="debug">
<label for="debug">Log debug message in the console</label>
</div>
Expand Down Expand Up @@ -181,7 +183,7 @@ <h2>Markdown</h2>
</table>
</div>

<button type="submit">Save</button
<button type="submit">Save</button>
</form>
<script src="options.js"></script>
</body>
Expand Down

0 comments on commit c4cbdcf

Please sign in to comment.