Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to disable link styling #45

Merged
merged 2 commits into from
Oct 14, 2019
Merged
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
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