cod

codedown

Extract code blocks from Markdown files

Showing:

Popularity

Downloads/wk

25

GitHub Stars

44

Maintenance

Last Commit

2mos ago

Contributors

0

Package

Dependencies

2

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Build Status Coverage Status npm version

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 | xargs -0 scala -e
42

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)
    

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100