Hi,
trying to make a small script which would translate wiki file into
LaTeX and when trying to translate possible HTML elements into LaTeX I
did this:
def latexEnvironmen ts(matchobj):
print >>sys.stderr,st r(matchobj.grou ps())
inStr = matchobj.group( 1)
translDict = {'dl': ('\\begin{descr iption}','\\end {description}') ,
'ol': ('\\begin{enume rate}','\\end{e numerate}'),
'ul': ('\\begin{itemi ze}','\\end{ite mize}'),
'blockquote': ('\\begin{quote }','\\end{quote }'),
'center': ('\\begin{cente r}','\\end{cent er}'),
'li': ('\\item',''),
'pre': ('\\begin{ttfam ily}','\\end{tt family}')}
if translDict.has_ key(inStr):
retTuple = translDict[inStr]
else:
retTuple = ('','')
if matchobj.group( 0) == '/':
return retTuple[1]
else:
return retTuple[0]
def latexHeadings(m atchobj):
print >>sys.stderr,st r(matchobj.grou ps())
inStr = matchobj.groups[1]
translDict = {'h1': '\\section{}',
'h2': '\\subsection{} ',
'h3': '\\subsubsectio n{}',
'h4': '\\subsubsubsec tion{}',
'h5': '\\paragraph{}' }
if translDict.has_ key(inStr) and (matchobj.group s[0] != '/'):
return translDict[inStr]
else:
return ''
def latexEmptyEleme nts(matchobj):
retString = ""
print >>sys.stderr,st r(matchobj.grou ps())
inStr = matchobj.group( 0)
translDict = {'br//': '\\\\',
'hr': '\\par{}\\hrule fill{}\\par{}'}
if translDict.has_ key(inStr):
return translDict[inStr]
else:
return ''
[... snip ...]
# Remove superfluous HTML elements
reEnvironments =
re.compile(r'<(/?)(dl|ol|ul|add ress|blockquote |center|del\
|ins|div|isinde x|noscript|p|pr e)>',re.IGNORE)
reHeadings = re.compile(r'<(/?)(h1|h2|h3|h4| h5|h6)>',re.IGN ORE)
reEmpty = re.compile(r'<( hr|br)\s*/?>',re.IGNORE)
body = reEnvironments. sub(latexEnviro nments,body)
body = reHeadings.sub( latexHeadings,b ody)
body = reEmpty.sub(lat exEmptyElements ,body)
The problem is that apparently RE never matches (and no function is
thus called). Can anybody tell me what's wrong with my REs, please?
Thanks for any help,
Matej
trying to make a small script which would translate wiki file into
LaTeX and when trying to translate possible HTML elements into LaTeX I
did this:
def latexEnvironmen ts(matchobj):
print >>sys.stderr,st r(matchobj.grou ps())
inStr = matchobj.group( 1)
translDict = {'dl': ('\\begin{descr iption}','\\end {description}') ,
'ol': ('\\begin{enume rate}','\\end{e numerate}'),
'ul': ('\\begin{itemi ze}','\\end{ite mize}'),
'blockquote': ('\\begin{quote }','\\end{quote }'),
'center': ('\\begin{cente r}','\\end{cent er}'),
'li': ('\\item',''),
'pre': ('\\begin{ttfam ily}','\\end{tt family}')}
if translDict.has_ key(inStr):
retTuple = translDict[inStr]
else:
retTuple = ('','')
if matchobj.group( 0) == '/':
return retTuple[1]
else:
return retTuple[0]
def latexHeadings(m atchobj):
print >>sys.stderr,st r(matchobj.grou ps())
inStr = matchobj.groups[1]
translDict = {'h1': '\\section{}',
'h2': '\\subsection{} ',
'h3': '\\subsubsectio n{}',
'h4': '\\subsubsubsec tion{}',
'h5': '\\paragraph{}' }
if translDict.has_ key(inStr) and (matchobj.group s[0] != '/'):
return translDict[inStr]
else:
return ''
def latexEmptyEleme nts(matchobj):
retString = ""
print >>sys.stderr,st r(matchobj.grou ps())
inStr = matchobj.group( 0)
translDict = {'br//': '\\\\',
'hr': '\\par{}\\hrule fill{}\\par{}'}
if translDict.has_ key(inStr):
return translDict[inStr]
else:
return ''
[... snip ...]
# Remove superfluous HTML elements
reEnvironments =
re.compile(r'<(/?)(dl|ol|ul|add ress|blockquote |center|del\
|ins|div|isinde x|noscript|p|pr e)>',re.IGNORE)
reHeadings = re.compile(r'<(/?)(h1|h2|h3|h4| h5|h6)>',re.IGN ORE)
reEmpty = re.compile(r'<( hr|br)\s*/?>',re.IGNORE)
body = reEnvironments. sub(latexEnviro nments,body)
body = reHeadings.sub( latexHeadings,b ody)
body = reEmpty.sub(lat exEmptyElements ,body)
The problem is that apparently RE never matches (and no function is
thus called). Can anybody tell me what's wrong with my REs, please?
Thanks for any help,
Matej