Skip to content

Instantly share code, notes, and snippets.

@vojtaholik
Created October 8, 2022 15:25
Show Gist options
  • Save vojtaholik/249fff11c396b252bb6485f027f4d125 to your computer and use it in GitHub Desktop.
Save vojtaholik/249fff11c396b252bb6485f027f4d125 to your computer and use it in GitHub Desktop.
// Name: Markdown to Portable Text
/** @type {import("@johnlindquist/kit")} */
const { markdownToRichText } = await npm("@tryfabric/martian");
const showdown = await npm("showdown");
const input = await getSelectedText();
const output = markdownToRichText(input);
const converter = new showdown.Converter();
const html = converter.makeHtml(input, {
omitExtraWLInCodeBlocks: true,
});
await exec(`
echo "${html}" | textutil -stdin -format html -convert rtf -stdout | pbcopy
`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment