-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update CopyAsMarkdown to add format options
- Loading branch information
Showing
4 changed files
with
76 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// #popclip | ||
// name: Copy as Markdown | ||
// identifier: com.pilotmoon.popclip.extension.copy-as-markdown | ||
// description: Copy web content as Markdown. | ||
// icon: '>md.png' | ||
// popclip version: 4225 | ||
|
||
const linkedom=require("linkedom"); | ||
const TurndownService=require("turndown"); | ||
|
||
exports.options = [ | ||
{ | ||
identifier: "headingStyle", | ||
label: "Heading Style", | ||
type: "multiple", | ||
values: ["atx", "setext"], | ||
valueLabels: ["ATX — # Heading", "Setext — Heading⏎======="], | ||
}, | ||
{ | ||
identifier: "bulletListMarker", | ||
label: "Bullet List Marker", | ||
type: "multiple", | ||
values: ["*", "-", "+"], | ||
}, | ||
{ | ||
identifier: "emDelimiter", | ||
label: "<em> Delimiter", | ||
type: "multiple", | ||
values: ["*", "_"], | ||
}, | ||
{ | ||
identifier: "strongDelimiter", | ||
label: "<strong> Delimiter", | ||
type: "multiple", | ||
values: ["**", "__"], | ||
}, | ||
{ | ||
identifier: "linkStyle", | ||
label: "Link Style", | ||
type: "multiple", | ||
values: ["inlined", "referenced"], | ||
valueLabels: ["Inline — [text](url)", "Reference — [text][id]"], | ||
} | ||
]; | ||
|
||
function htmlToMarkdown(html, options) { | ||
// generate DOM object from HTML | ||
function JSDOM(html) { | ||
return linkedom.parseHTML(html); | ||
} // facade to work like jsdom | ||
const { document } = new JSDOM(html); | ||
// extract markdown using turndown | ||
const turndownService = new TurndownService(options); | ||
return turndownService.turndown(document); | ||
} | ||
|
||
exports.action = { | ||
captureHtml: true, | ||
code(input, options) { | ||
popclip.copyText(htmlToMarkdown(input.html, options)); | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters