Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gautamarora/2592250 to your computer and use it in GitHub Desktop.
Save gautamarora/2592250 to your computer and use it in GitHub Desktop.
simple edit to the convert command in textmate markdown bundle to save the generated html as a .html file in same dir
# This command works well when you use the TextMate service from a
# web-log editor like Ecto or MarsEdit. You can write in markdown
# and then convert back to html before save and close.
HTML4=$([ -n "$TM_XHTML" ] || echo '--html4tags')
"${TM_MARKDOWN:-Markdown.pl}" $HTML4 > "$TM_FILENAME".html|"${TM_SMARTYPANTS:-SmartyPants.pl}"|perl -pe '
# make <h1>Header</h1> into <h1 id="header">Header</h1>
# so that we can link to page#header
if(($tag, $title) = /<(h[1-6])>(.*?)<\/\1>/) {
$_ = $title;
s/<[^>]+>|&\w+;//g; # remove tag and entities
s/[^-_ \/\w]//g; # remove all but word and separators
s/[-_ \/]+/_/g; # collapse all separators into _
$_ = "<$tag id=\"" . (lc $_) . "\">$title</$tag>\n";
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment