Giter VIP home page Giter VIP logo

showdown-copy-code's Introduction

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's People

Contributors

piotrpdev avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.