npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

2md

v0.0.8

Published

convert formatted text to markdown

Downloads

42

Readme

2md: convert formatted text to markdown

There are lots of packages for turning markdown into html, but this one goes the other way, turning formatted html into markdown.

Say you’re reading an Ars Technica article and want to copy something into some markdown notes. Just select some content in your browser, copy it, then run 2md. The heading, list formatting, bold text, and hyperlinks are all preserved.

You can try it out online at 2md.ca.

A detailed writeup of the internals exists: “Compiling HTML to Markdown with TypeScript: How 2md works

Installation

The easiest way to try out 2md from the command line is with npx, a tool to automatically download, cache, and run programs; it’s been included with Node.js since 2017:

npx 2md [--no-quote] [FILE]

You can also install to install the 2md command with yarn:

yarn [global] add 2md

Usage

Run

npx 2md [--no-quote] [FILE]

to get markdown.

By default, 2md reads from the clipboard, using osascript, xclip, or powershell. Otherwise, pass it the name of html file as a command-line argument.

For easy inserting of stuff into other documents, --quote is on by default and wraps the markdown in a blockquote:

> # Foo
>
> bar ...

API

Only a single function is exposed: toMd.

const { toMd } = require('2md');

console.log(toMd('foo <b>bar</b>'));

prints

foo **bar**

Only exported files with public in the path are supported. Everything else is subject to change without notice. But if there’s some interesting code here you’d like to reuse, let me know and I can look into publishing it as a separate package.

Contributing

Contributions are welcome! There are fairly comprehensive end-to-end and round-trip tests, and TypeScript’s type-checking makes refactoring safer, so don’t be afraid to move code around.

License

All the original code here is licensed under the Apache License, version 2.0, included in LICENSE.code; except for the contents of the “how it works” article how-it-works/post.mdx, which is not redistributable.

Releasing

The current release process, to be automated later, is:

  1. Remove the -pre tag from the version field in core/package.json version, and from the 2md dependency in website/package.json

  2. Update CHANGELOG.md

  3. Copy README.md and any referenced images such as doc/demo.gif into the core folder

  4. Commit to git, and git tag vA.B.C

  5. In the core directory, yarn run package and inspect tarball

  6. git push --atomic $REMOTE main vA.B.C

    Optional: figure out automation to put CHANGELOG.md excerpt into auto-created GitHub releases.

  7. npm publish 2md-vA.B.C.tgz

    If publishing a pre-release, add npm publish --tag next to set the correct npm tag.

  8. Bump version and add -pre version suffix in core/package.json; update the 2md dependency version in website/package.json as well

  9. For the precompiled version, run yarn dist in core and copy 2md.js to ~/bin. It relies on a shell wrapper:

    #!/bin/bash
    
    DIR="$(dirname -- "${0}")"
    
    exec node "${DIR}/2md.js" "${@}"