Skip to content

Instantly share code, notes, and snippets.

@losinggeneration
Created January 12, 2014 08:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save losinggeneration/8382292 to your computer and use it in GitHub Desktop.
Save losinggeneration/8382292 to your computer and use it in GitHub Desktop.
Lua markdown
function markdown()
{
lua5.1 <(echo "$(cat << EOLUA
discount=require("discount")
if #arg > 0 then
for _,v in ipairs(arg) do
local lines = ""
local f = io.open(v, "r")
if not f then
io.output(io.stderr):write(string.format([[%s: No such file or directory\n]], v))
os.exit(1)
end
io.write(discount(f:read("*a")))
f:close()
end
else
local lines = ''
while true do
local line = io.read()
if not line then
break
end
lines = string.format('%s\\\n%s', lines, line)
end
io.write(discount(lines))
end
EOLUA
)") $*
}
function mdcat()
{
if [ $# = 0 ]; then
markdown | pandoc -t plain -f html
else
markdown < $* | pandoc -t plain -f html
fi
}
function mdmore()
{
mdcat $* | more
}
function mdless()
{
mdcat $* | less
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment