Extract code blocks from Markdown files
JavaScript
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib Make portable between npm and web browser Jul 10, 2018
test
.travis.yml Update to NodeJS 6 Jan 5, 2018
README.md Update the online demo link Jul 10, 2018
codedown.gif A bit more May 18, 2016
codedown.js
package.json Set version to 2.1.5 Jul 10, 2018

README.md

Build status Coverage status

Codedown is a little utility to extract code blocks from Markdown files.

Inspired by literate Haskell, codedown can be used to:

  • Validate the correctness of code embedded in Markdown
  • Run code embedded in Markdown
  • Ship code and Markdown together in harmony

Quicker start

To skip installing codedown locally, try it online.

Quick start

Install codedown:

$ npm install -g codedown

Run codedown:

$ codedown
usage: codedown <lang>
ex: codedown haskell

Codedown reads Markdown from stin, extracts the code blocks designated as language <lang>, and outputs them to stdout.

You can pipe the output of codedown to a language interpreter:

$ cat README.md | codedown haskell | runhaskell
42
$ cat README.md | codedown javascript | node
42
$ cat README.md | codedown scala | scala
scala> val x = 42
x: Int = 42
scala> println(x)
42
scala> :quit

Examples

This readme is a Markdown file, so we can use codedown to extract code from it.

In the following code blocks, let's set x to 42 in different languages:

Haskell:

x :: Int
x = 42

JavaScript:

var x = 42;

Scala:

val x = 42

Now let's print x it to stdout in different languages.

This time, the code blocks are nested within an unordered list:

  • Haskell:

    main :: IO ()
    main = putStrLn $ show x
  • JavaScript:

    console.log(x);
  • Scala:

    println(x)