|
|
|
|
@ -4,7 +4,7 @@ from HTMLParser import HTMLParser |
|
|
|
|
|
|
|
|
|
class MDHTML2TexParser(HTMLParser): |
|
|
|
|
txt='' |
|
|
|
|
oul=False |
|
|
|
|
pre=False |
|
|
|
|
def handle_starttag(self, tag, attrs): |
|
|
|
|
if tag=='h2': |
|
|
|
|
self.txt+='\\section{' |
|
|
|
|
@ -19,14 +19,18 @@ class MDHTML2TexParser(HTMLParser): |
|
|
|
|
|
|
|
|
|
if tag=='ul': |
|
|
|
|
self.txt+='\\begin{itemize}\n' |
|
|
|
|
self.oul=True |
|
|
|
|
if tag=='ol': |
|
|
|
|
self.txt+='\\begin{enumerate}\n' |
|
|
|
|
self.oul=True |
|
|
|
|
if tag=='li': |
|
|
|
|
self.txt+='\\item ' |
|
|
|
|
if tag=='p': |
|
|
|
|
self.txt+='\n\n' |
|
|
|
|
if tag=='pre': |
|
|
|
|
self.txt+='\\begin{verbatim}' |
|
|
|
|
self.pre=True |
|
|
|
|
if tag=='code' and not self.pre: |
|
|
|
|
self.txt+='\\texttt{' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle_endtag(self, tag): |
|
|
|
|
if tag=='h2' or\ |
|
|
|
|
@ -34,21 +38,36 @@ class MDHTML2TexParser(HTMLParser): |
|
|
|
|
tag=='h4': |
|
|
|
|
self.txt+='}\n' |
|
|
|
|
if tag=='strong' or\ |
|
|
|
|
tag=='em': |
|
|
|
|
tag=='em' or\ |
|
|
|
|
tag=='code' and not self.pre: |
|
|
|
|
self.txt+='}' |
|
|
|
|
if tag=='ul': |
|
|
|
|
self.txt+='\\end{itemize}\n' |
|
|
|
|
if tag=='ol': |
|
|
|
|
self.txt+='\\end{enumerate}\n' |
|
|
|
|
|
|
|
|
|
if tag=='pre': |
|
|
|
|
self.txt+='\\end{verbatim}' |
|
|
|
|
self.pre=False |
|
|
|
|
|
|
|
|
|
def handle_data(self, data): |
|
|
|
|
self.txt+=data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eref = { 'lt':'<', |
|
|
|
|
'gt':'>', |
|
|
|
|
'quot':'"', |
|
|
|
|
'amp':'&' } |
|
|
|
|
def handle_entityref(self,ref): |
|
|
|
|
self.handle_charref(ref) |
|
|
|
|
def handle_charref(self,ref): |
|
|
|
|
if self.body: |
|
|
|
|
if ref in self.eref: |
|
|
|
|
self.txt+=self.eref[ref] |
|
|
|
|
else: |
|
|
|
|
self.txt += '&'+ref+';' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle_charref(self,ref): |
|
|
|
|
self.txt += unichr(ref) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not(len(sys.argv)==3 or len(sys.argv)==2): |
|
|
|
|
print "Usage: %s infile [outfile] " % sys.argv[0] |
|
|
|
|
@ -68,6 +87,7 @@ f.write(""" |
|
|
|
|
\\usepackage[T1]{fontenc} |
|
|
|
|
\\usepackage[ngerman]{babel} |
|
|
|
|
\\usepackage{amsmath} |
|
|
|
|
\\textbf{k-COLORING}\parindent0mm |
|
|
|
|
|
|
|
|
|
\\title{Ein Testdokument} |
|
|
|
|
\\author{Otto Normalverbraucher} |
|
|
|
|
|