Created
January 12, 2014 08:32
-
-
Save losinggeneration/8382292 to your computer and use it in GitHub Desktop.
Lua markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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