showdown-copy-code
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

showdown-copy-code

Version

Showdown extension that adds a button above code blocks to quickly and easily copy code to the clipboard.

Yoinked Heavily inspired by this project (go check out the creator).

How do I install it?

npm install showdown-copy-code

Usage

Yoinked Heavily inspired by the showdown-highlight example.

const showdown = require("showdown");
const showdownHighlight = require("showdown-highlight");
const { showdownCopyCode } = require("showdown-copy-code");

let converter = new showdown.Converter({
  extensions: [showdownHighlight, showdownCopyCode],
});

const html = converter.makeHtml(`
## Highlighting Code with Showdown

Below we have a piece of JavaScript code:

<br>

\`\`\`js
document.querySelector('#master-yoda')
// => <div id="master-yoda">Yoda</div>

document.querySelector('.class-of-assassins')
// => <div class="class-of-assassins">Assassin</div>

document.querySelector('p')
// => <p>The three little pigs</p>

document.querySelector('[data-type="rocket"]')
// => <div data-type="rocket">🚀</div>
\`\`\`
`);

console.log(html);

Warning

  • ONLY FULLY WORKS IN BROWSER (Adds an event listener to the window to detect button clicks). If you load the module serverside AND on the browser, you may be able to call showdownCopyCode.addListener() on the browser. Otherwise, you need to do your own implementation.

  • Styles not included out of the box.

  • Needs testing.

  • Need to make sure the fix for the showdown-highlight pre option doesn't mess up.

  • Uses navigator.clipboard, which might need a polyfill on older browsers.

Q&A

Why { showdownCopyCode } instead of showdownCopyCode?

Default vs Named exports.

License

MIT

Resources Used/Help/Credit

/showdown-copy-code/

    Package Sidebar

    Install

    npm i showdown-copy-code

    Weekly Downloads

    27

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    23.1 kB

    Total Files

    8

    Last publish

    Collaborators

    • piotrpdev-owner
    • piotrpdev