public
Last active

Format program listings for Markdown

  • Download Gist
pbook in sed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
sed -E -e 's/^/ /g' -e 's/^ --- ?//g' | pandoc -o listing.pdf -
 
That expression is a cheap literate programming system for Markdown.
Start commentary lines with '--- ' and they will be
markdown-formatted, the rest will be code. (Uses Lua comment syntax.)
 
Finally the right implementation of this idea:
http://fresh.homeunix.net/~luke/misc/emacs/pbook.pdf (program)
http://fresh.homeunix.net/~luke/misc/erlang/regtest.pdf (better example)
 
EXAMPLE INPUT:
 
--- ## Linux glue
---
--- To take direct control of a PCI device on Linux requires a little
--- setup. This is facilitated by the sysfs (`/sys`) filesystem which
--- supports finding devices, checking their type, forcing kernel
--- drivers to unbind them, and other handy things. (sysfs is one great
--- Linux feature.)
 
function pcidev_is_82574 (device)
return io.open(path(device,"config"), "ro"):read(4) == "\x86\x80\xd3\x10"
end
 
EXAMPLE OUTPUT:
 
## Linux glue
 
To take direct control of a PCI device on Linux requires a little
setup. This is facilitated by the sysfs (`/sys`) filesystem which
supports finding devices, checking their type, forcing kernel
drivers to unbind them, and other handy things. (sysfs is one great
Linux feature.)
function pcidev_is_82574 (device)
return io.open(path(device,"config"), "ro"):read(4) == "\x86\x80\xd3\x10"
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.