A React Hook to Copy Text as Markdown


A React hook to copy text as Markdown.


Copying text as Markdown is helpful for blog posts or documentation pages that were authored in Markdown and may be copied into other documents or code comments. Instead of copying plain text or rich text, this utility will copy the selected content as Markdown.


See it in action

Check out blog posts on cpojer.net, for example Principles of Developer Experience, and copy text within the article. The text will be copied as Markdown.



yarn add @cnakazawa/copy-as-markdown


import useCopyAsMarkdown from '@cnakazawa/copy-as-markdown';

export default function MyComponent() {
  const setRef = useCopyAsMarkdown();

  return (
    <div ref={setRef}>
      <h1>When copied, this will turn into Markdown</h1>
      Any <em>rich content</em> inside of this container will be copied as <strong>

This library uses turndown to convert HTML to Markdown. You can pass any turndown Options to the useCopyAsMarkdown hook:

const setRef = useCopyAsMarkdown({
  bulletListMarker: '-',
  strongDelimiter: '__',

Download Details:

Author: cpojer
Live Demo: View The Demo
Download Link: Download The Source Code
Official Website: https://github.com/cpojer/copy-as-markdown
License: MIT

#react #javascript #web-development #markdown

A React Hook to Copy Text as Markdown
3.65 GEEK