Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

hysencn/codedown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

50 Commits

Repository files navigation

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)

About

Extract code blocks from Markdown files

Resources

Stars

Watchers

Forks

Packages

Contributors

Languages

  • JavaScript 100.0%

AltStyle によって変換されたページ (->オリジナル) /