Skip to content

Instantly share code, notes, and snippets.

@tiye
Created January 29, 2012 11:36
Show Gist options
  • Save tiye/1698405 to your computer and use it in GitHub Desktop.
Save tiye/1698405 to your computer and use it in GitHub Desktop.
`Garrett Flavored Markdown`编译脚本
#!/usr/bin/env coffee
# 需要`showdown`脚本, 最后加上`xports.converter = new Showdown.converter()`导出为模块
# http://github.github.com/github-flavored-markdown/scripts/showdown.js
# 然后在该目录用`$ coffee #{这个文件的名字}.coffee #{需要编译的文件名}.gfm`来运行
# 我将用作常用的工具, 但这个不知道怎么高亮语法, 没办法了, 先这样用着
style = """
body{
background: hsl(0,96%,96%);
font-size: 13px;
line-height: 26px;
}
p>code, pre{
padding: 0px 3px;
margin: 0px 3px;
background: hsl(0,94%,94%);
border: 1px solid hsl(0,96%,80%);
}
p{
margin: 0px;
}
pre{
margin: 0px;
}
a{
color: hsl(240,40%,50%);
text-decoration: none;
}
"""
o = console.log
converter = (require './showdown').converter
fs = require 'fs'
argvs = process.argv
unless argvs.length is 3
o 'Result from Argvs: ', argvs
o 'Any file?'
else
o argvs[2]
source = (argvs[2].match /(^.+)\.gfm/)
unless source
o 'Result from Regex: ', source
o 'Probably wrong filename'
else
# unless source['1'] then o 'Can\'t find .gfm File'
# else
filename = source['1'] + '.gfm'
file = fs.readFileSync filename, 'utf-8'
html =
"
<style>
#{style}
</style>
"
html += converter.makeHtml file
new_filename = source['1'] + '.html'
fs.writeFileSync(new_filename, html, encoding='utf8')
o 'Wrote to .html file: ', new_filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment