Skip to content

About

Convert rich-text on your clipbaord to markdown

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

clipboard2markdown

Easily convert richly formatted text or HTML to Markdown. Use the clipboard and paste to Markdown with a single keypress.

The conversion is carried out by Turndown (formerly to-markdown), a Markdown converter running in the browser.

Demo

Interactive

http://euangoddard.github.io/clipboard2markdown/

Video

Screencast: copying a formatted article, pasting it into the app and copying the converted Markdown

Usage

Open the app, copy some rich text and press Ctrl+V (or ⌘+V on Mac) anywhere on the page.

The converted Markdown is selected, ready to copy with Ctrl+C (or ⌘+C), or use the Copy button.

One can paste multiple times. A paste replaces the selected text, so pasting straight after a conversion overwrites it; place the cursor in the output first to insert at that point instead.

Typographic punctuation (“curly quotes”, en and em dashes, the ellipsis) is kept as pasted. Switch on Pandoc ASCII punctuation to write it the way Pandoc's smart extension expects instead (", ', --, ---, ...). The browser remembers the choice.

Development

The app is built with Solid 2 and Vite, and tested with Vitest.

npm install
npm run dev        # start a development server
npm test           # run the test suite
npm run typecheck  # type-check with TypeScript
npm run build      # production build in dist/

Layout

  • src/converter/ holds the HTML to Markdown conversion: Turndown configured with the original Pandoc, GFM and Markdown rules, plus the Pandoc clean-up of line breaks and, optionally, punctuation. The switch's "Pandoc ASCII punctuation" is 'ascii' punctuation in the code; off is 'typographic'.
  • src/App.tsx is the page: the paste shortcut, the hidden paste target, the punctuation switch, and the output.
  • src/punctuationPreference.ts remembers the punctuation choice in localStorage.
  • legacy/ is the original implementation, kept unmodified as a test oracle.

Tests

The suite checks that the rewrite reproduces the original behaviour. The original always wrote ASCII punctuation, so the parity tests run with it switched on:

  • test/converter.test.ts specifies every conversion rule. Each expectation is asserted against both the original converter and the new one.
  • test/parity.test.ts compares the two converters on a corpus and on thousands of seeded random documents. The few intentional differences are listed there; all of them fix whitespace bugs in the original.
  • test/appParity.test.tsx runs the original page and the new app through the same user journeys (shortcut, paste, caret placement, repeated pastes) and compares their state after every step.
  • test/app.test.tsx, test/insertText.test.ts, test/pasteShortcut.test.ts, test/cleanUp.test.ts and test/punctuationPreference.test.ts cover the individual pieces.

About

clipboard2markdown was created by Euan Goddard. The original version used html2markdown by Kates Gasis and Himanshu Gilani. Vegard Øye ported it to to-markdown by Dom Christie, which has since become Turndown. Version 2 is a rewrite in Solid on Turndown.

License

License

Released under the MIT License. See the LICENSE file for details.

About

Convert rich-text on your clipbaord to markdown

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages