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).
npm install showdown-copy-code
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);
-
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.
Why
{ showdownCopyCode }
instead ofshowdownCopyCode
?
MIT