代码: 全选#!/usr/bin/env python
import os, sys
def source2html(filename):
'''Use vim to dump syntax and indent to a html file'''
cmd = 'vim -c ":syntax on|:colorscheme morning|:TOhtml" -c ":wq!|:q!" %s' %(filename)
os.system(cmd)
def html2wiki(filename):
'''Use sed command to convert html syntax to tiddlywiki syntax'''
sedcmd = '''s/http/|http/g;
s//]]/g;
s/
s/color="/color(/g;
s/]*>//g;
s///g;
s/">/):/g;
s//@@/g;
/
/ d;
/
/ d;// d;
/
/ d;/
/ d;/
/
// d;
// d;
// d;
// d;
s/\/\//\/ \//g'''
cmd = "sed -e '%s' %s > %s" %(sedcmd, filename, filename+'.wiki')
os.system(cmd)
if __name__=='__main__':
for file in sys.argv[1:]:
#Step 1, source to html
source2html(file)
#Step 2, html to tiddlywiki
html2wiki(file+'.html')
#Step 3, remove useless html files
os.remove(file+'.html')