fence-filter

Fence or unfence code blocks in markdown files

npm install fence-filter
2 downloads in the last week
4 downloads in the last month

Fence

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 README.md 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.

Example

Suppose we have a file, demo.python.md, 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

```python
print "hello world!"
```

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

print "hello world!"

Usage

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

You can also "undo" fencing:

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

Round-trip:

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

Credit

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

npm loves you