Fence or unfence code blocks in markdown files
npm install fence-filter
|2||downloads in the last month|
|Version||0.0.1 last updated 11 months ago|
|Keywords||markdown, filter, utility, literate scripting|
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.
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!"
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
fence demo.litcoffee | fence --undo > demo.litcoffee
HT to @jashkenas, this is but a tweak of journo's Cakefile.