Skip to content

Commit

Permalink
feat(debug): add debug setting and issue template
Browse files Browse the repository at this point in the history
  • Loading branch information
0x6b committed Dec 17, 2018
1 parent 3463cd2 commit d1dbd05
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

**Actual Result**

<!--
1. Click the menu button and choose Add-ons.
2. In the Add-ons Manager tab, select the Extensions panel.
3. Find **Copy Selection as Markdown** and click **More**.
4. Check **Log debug message in the console** and click **Save**.
5. Click the menu button and choose **Web Developer** then **Web Console**.
6. Copy your text again.
7. Paste console output to here.
-->

**Expected Result**
11 changes: 11 additions & 0 deletions src/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ async function main() {
options.linkStyle = typeof options.linkStyle === "undefined" ? "inlined" : options.linkStyle;
options.linkReferenceStyle =
typeof options.linkReferenceStyle === "undefined" ? "full" : options.linkReferenceStyle;
options.debug = typeof options.debug === "undefined" ? true : options.debug;

let text = `[${document.title}](${document.URL})`;
let selection = getSelectionAsMarkdown(options);
Expand All @@ -32,6 +33,16 @@ async function main() {
}
}

if (config["debug"]) {
console.log("/* --- copy-selection-as-markdown debug information --- */");
console.log("/* --- INPUT ------------------------------------------ */");
console.log(result.html);
console.log("/* --- OUTPUT------------------------------------------ */");
console.log(result.output);
console.log("/* --- URL -------------------------------------------- */");
console.log(result.url);
console.log("/* ---------------------------------------------------- */");
}
doCopy(text);
} catch (e) {
console.error(e);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ turndownService.addRule("mathjax-remove-inline-formula", {
turndownService.addRule("mathjax-paragraph-before-script-node", {
filter: "p",

replacement: function (content, node) {
replacement: function(content, node) {
var hasSiblings = node.nextSibling;

if (
Expand Down Expand Up @@ -87,7 +87,7 @@ const getSelectionAsMarkdown = () => {
html = container.innerHTML;
}

return turndownService.turndown(html);
return { html, output: turndownService.turndown(html), url: document.URL };
};

const doCopy = text => {
Expand Down
5 changes: 4 additions & 1 deletion src/settings/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ document.addEventListener("DOMContentLoaded", () => {
typeof result.linkStyle === "undefined" ? "inlined" : result.linkStyle;
document.querySelector("form").linkReferenceStyle.value =
typeof result.linkReferenceStyle === "undefined" ? "full" : result.linkReferenceStyle;
document.querySelector("#debug").checked =
typeof result.debug === "undefined" ? true : result.debug;
},
error => console.log(`Error: ${error}`)
);
Expand All @@ -37,6 +39,7 @@ document.querySelector("form").addEventListener("submit", e => {
emDelimiter: document.querySelector("form").emDelimiter.value,
strongDelimiter: document.querySelector("form").strongDelimiter.value,
linkStyle: document.querySelector("form").linkStyle.value,
linkReferenceStyle: document.querySelector("form").linkReferenceStyle.value
linkReferenceStyle: document.querySelector("form").linkReferenceStyle.value,
debug: document.querySelector("#debug").checked
});
});
2 changes: 2 additions & 0 deletions src/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ <h2>General</h2>
<label for="quote">Append quote (<code>&gt;</code>) to selection</label>
<input type="checkbox" id="link">
<label for="link">Include link to source web page in the beginning of copied text</label>
<input type="checkbox" id="debug">
<label for="debug">Log debug message in the console</label>
</div>
<div>
<h2>Markdown</h2>
Expand Down

0 comments on commit d1dbd05

Please sign in to comment.