node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



Convert your literate script to a GH-flavored code-fenced variant ... or vice versa.

Handy if you want to have your code blocks highlighted when posting your literate script as a Gist or as a file for your repo ... or to convert a markdown file with fenced code blocks to literate source.

Note that this utility only converts code blocks in markdown files from one format to another. See this gist for a demonstration of how to run or extract code blocks from any literate source file.


Suppose we have a file,, containing ...

# Demo

    print "hello world!"

And now we want to fence the code blocks in this file so that they'll be rendered nicely when people look at our demo file on Github. That is, we want ...

# Demo

print "hello world!"

... so that the codeblock is rendered all pretty:

print "hello world!"


fence >
fence >
fence demo.litcoffee >
cat | fence --lang python >
cat | fence --lang coffee >

You can also "undo" fencing:

fence --undo > demo.litcoffee
cat | fence --undo > demo.litcoffee


fence demo.litcoffee | fence --undo > demo.litcoffee


HT to @jashkenas, this is but a tweak of journo's Cakefile.