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 🙏

© 2026 – Pkg Stats / Ryan Hefner

markdown-code-extract

v1.0.2

Published

Extract dedicated code blocks from markdown files to 'real' code files for validation, application, reusing etc.

Downloads

161

Readme

Extract dedicated code blocks from markdown files to "real" code files

Scan a Markdown file for code blocks prepended with a local file link and write the code block's content to the file defined in the link, the file / path of the link are created if not existing yet.

Basic use case is e.g. to validate code examples in a README.md, use them directly for automated tests and reuse them for demos, i.e. to avoid the effort and notorious errors with copy and paste of code and divergence of intentionally identical code at different places.

Also possible is e.g. extracting examples from the README.md of another project to reuse them in the current project or pushing examples of the current project to a centralized storage.

The basic idea and code is forked from the ingenious markdown-code-extractor (v1.4.0).

hh lohmann <[email protected]>

Synopsis

  import { markdownCodeExtract } from 'markdown-code-extract'

  [await] markdownCodeExtract()

  [await] markdownCodeExtract(mdFile)

  [await] markdownCodeExtract(mdFile,outputRoot)

  [await] markdownCodeExtract('examples.md')

  [await] markdownCodeExtract('../examples/js.md')

  [await] markdownCodeExtract('#','../examples/js.md')

Parameters

mdFile

Optional: Name / path of Markdown file to extract code blocks from

  • Default: ./README.md
  • Use placeholder # for 'use default' if you only want to specify other parameters

outputRoot

Optional: Path of an existing directory to write code files to

  • Default: ./
  • Use placeholder # for 'use default' if you only want to specify other parameters

logLevel

Optional: Log process details

  • Possible values: 0 = no logging, 1 = some logging
  • Default: 0
  • Use placeholder # for 'use default' if you only want to specify other parameters

Returns

Promise

  • Since markdownCodeExtract mainly acts as a batch with error throwing you may need only .catch but not await / .then

Demo

Dependencies

  • npm packages:
    • is-binary-file-simple: Check with minimal effort if a file is binary, e.g. before trying to apply text file methods

Installation

Pick for your preferred package manager:

  npm i markdown-code-extract
  pnpm i markdown-code-extract
  bun i markdown-code-extract
  # For Yarn you should double check docs for your and / or
  # current Yarn version, newer versions do not treat `i package_name`
  # as an alias for `add ...` and exclude global installations
  yarn add markdown-code-extract

Source Code

License

References

is-binary-file-simple

markdown-code-extractor