From 417ba3454c416ceae5f00f2742d496b32aee1623 Mon Sep 17 00:00:00 2001 From: kaoru <679719+0x6b@users.noreply.github.com> Date: Mon, 14 Oct 2019 20:59:40 +0900 Subject: [PATCH 1/2] fix: path to octicons after deps update --- src/icons/generate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icons/generate.js b/src/icons/generate.js index 38e8405..bc7d338 100644 --- a/src/icons/generate.js +++ b/src/icons/generate.js @@ -1,6 +1,6 @@ const { clippy: { path } -} = require("octicons"); +} = require("@primer/octicons"); const { writeFileSync } = require("fs"); const { resolve } = require("path"); const { parseString } = require("xml2js"); From ce8ac918a368a998e874aeed066f0667fba33eaa Mon Sep 17 00:00:00 2001 From: kaoru <679719+0x6b@users.noreply.github.com> Date: Mon, 14 Oct 2019 21:00:54 +0900 Subject: [PATCH 2/2] feat: add option to disable link styling --- src/copy.js | 6 +++++- src/lib/turndown-plugin-link-without-styling.js | 6 ++++++ src/lib/util.js | 5 +++++ src/options.js | 2 ++ src/settings.html | 4 +++- 5 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/lib/turndown-plugin-link-without-styling.js diff --git a/src/copy.js b/src/copy.js index c625788..cf353f4 100644 --- a/src/copy.js +++ b/src/copy.js @@ -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 !== "") { diff --git a/src/lib/turndown-plugin-link-without-styling.js b/src/lib/turndown-plugin-link-without-styling.js new file mode 100644 index 0000000..50d252b --- /dev/null +++ b/src/lib/turndown-plugin-link-without-styling.js @@ -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}"` : ""})` + }); +} diff --git a/src/lib/util.js b/src/lib/util.js index 22b1dbb..45da844 100644 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -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"; @@ -24,6 +25,10 @@ const getSelectionAsMarkdown = options => { turndownService.use(turndownPluginImg); } + if (options.linkWithoutStyling) { + turndownService.use(turndownPluginLinkWithoutStyling) + } + let html = ""; let sel = document.getSelection(); diff --git a/src/options.js b/src/options.js index 4e23d73..8a82e7c 100644 --- a/src/options.js +++ b/src/options.js @@ -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}`) @@ -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 }); }); diff --git a/src/settings.html b/src/settings.html index c54e7a9..c5af4cb 100644 --- a/src/settings.html +++ b/src/settings.html @@ -53,6 +53,8 @@