Skip to content

Instantly share code, notes, and snippets.

@tayiorbeii
Created February 9, 2023 22:36
Show Gist options
  • Save tayiorbeii/7c69d868b50748f520c4131f7a398090 to your computer and use it in GitHub Desktop.
Save tayiorbeii/7c69d868b50748f520c4131f7a398090 to your computer and use it in GitHub Desktop.
import "@johnlindquist/kit"
// Name: page to markdown
let { extract } = await npm('@extractus/article-extractor')
let TurndownService = await npm('turndown')
let input = await getActiveTab()
let turndownService = new TurndownService({codeBlockStyle: 'fenced'})
turndownService.addRule('codeBlock', {
filter: ['pre'],
replacement: (content) => {
return '```\n' + content + '\n```';
},
});
extract(input)
.then(async article => {
let { title, content } = article
let markdown = `# ${title}\n\n${turndownService.turndown(content)}`
// using Script Kit's file system api
// write markdown with the title of the page as a filename
// to the ~/Documents/Scraped Markdown folder
let path = `/Users/taylor/Documents/Scraped Markdown/${title}.md`
await ensureFile(path)
await writeFile(path, markdown)
debugger;
})
.catch(err => console.error(err))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment