hgbook
changeset 556:dbb4c40e2609
Fix some awful infelicities by replacing them with worse ones
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Mon Feb 09 23:03:44 2009 -0800 (2009-02-09) |
parents | b08f6a61bf15 |
children | 23dc79421e06 |
files | tools/latex-to-docbook |
line diff
1.1 --- a/tools/latex-to-docbook Mon Feb 09 22:59:50 2009 -0800 1.2 +++ b/tools/latex-to-docbook Mon Feb 09 23:03:44 2009 -0800 1.3 @@ -16,21 +16,22 @@ 1.4 'codesample2': 'programlisting', 1.5 'codesample4': 'programlisting', 1.6 'enumerate': 'orderedlist', 1.7 - 'figure': 'figure', 1.8 + 'figure': 'informalfigure', 1.9 'itemize': 'itemizedlist', 1.10 'note': 'note', 1.11 'quote': 'blockquote', 1.12 } 1.13 1.14 def process(ifp, ofp): 1.15 + print >> ofp, '<!-- vim: set filetype=docbkxml shiftwidth=2 autoindent expandtab tw=77 : -->\n' 1.16 stack = [] 1.17 para = True 1.18 - inlist = False 1.19 + inlist = 0 1.20 for line in ifp: 1.21 if line.startswith('%%% Local Variables:'): 1.22 break 1.23 line = (line.rstrip() 1.24 - .replace(' ', ' ') 1.25 + .replace('~', ' ') 1.26 .replace('&', '&') 1.27 .replace('&emdash;', '&emdash;') 1.28 .replace('\_', '_') 1.29 @@ -41,8 +42,8 @@ 1.30 .replace('\#', '#') 1.31 .replace('<', '<') 1.32 .replace('>', '>') 1.33 - .replace('<quote>', '<quote>') 1.34 - .replace("</quote>", '</quote>') 1.35 + .replace('``', '<quote>') 1.36 + .replace("''", '</quote>') 1.37 .replace('\\', '\\')) 1.38 line = re.sub(r'\s*\\(?:centering|small)\b\s*', '', line) 1.39 line = re.sub(r'\\(?:hgrc\\|hgrc)\b', 1.40 @@ -68,7 +69,7 @@ 1.41 line = re.sub(r'\\hgcmd{(?P<cmd>[^}]+)}', 1.42 r'<command role="hg-cmd">hg \g<cmd></command>', line) 1.43 line = re.sub(r'\\caption{(?P<text>[^}]+?)}', 1.44 - r'<caption>\g<text></caption>', line) 1.45 + r'<caption><para>\g<text></para></caption>', line) 1.46 line = re.sub(r'\\grafix{(?P<name>[^}]+)}', 1.47 r'<mediaobject><imageobject><imagedata fileref="\g<name>"/></imageobject><textobject><phrase>XXX add text</phrase></textobject></mediaobject>', line) 1.48 line = re.sub(r'\\envar{(?P<name>[^}]+)}', 1.49 @@ -103,7 +104,7 @@ 1.50 r'<command>\g<cmd></command>', line) 1.51 line = re.sub(r'\\option{(?P<opt>[^}]+)}', 1.52 r'<option>\g<opt></option>', line) 1.53 - line = re.sub(r'\\ref{(?P<id>[^}]+)}', r'<xref id="\g<id>"/>', line) 1.54 + line = re.sub(r'\\ref{(?P<id>[^}]+)}', r'<xref linkend="\g<id>"/>', line) 1.55 line = re.sub(r'\\emph{(?P<txt>[^}]+)}', 1.56 r'<emphasis>\g<txt></emphasis>', line) 1.57 line = re.sub(r'\\texttt{(?P<txt>[^}]+)}', 1.58 @@ -149,15 +150,20 @@ 1.59 env = envs[env] 1.60 if state == 'begin': 1.61 ofp.write('<') 1.62 - if env == 'itemizedlist': 1.63 - inlist = True 1.64 + if env in ('itemizedlist', 'orderedlist'): 1.65 + inlist = 1 1.66 else: 1.67 ofp.write('</') 1.68 - if env == 'itemizedlist': 1.69 - inlist = False 1.70 + if env == ('itemizedlist', 'orderedlist'): 1.71 + inlist = 0 1.72 print >> ofp, env + '>' 1.73 else: 1.74 if line.startswith('\\item '): 1.75 + if inlist > 1: 1.76 + print >> ofp, '</para>' 1.77 + print >> ofp, '</listitem>' 1.78 + else: 1.79 + inlist = 2 1.80 para = True 1.81 line = line[6:] 1.82 if line and para: 1.83 @@ -173,7 +179,7 @@ 1.84 print >> ofp, line 1.85 while stack: 1.86 print >> ofp, '</%s>' % stack.pop() 1.87 - ofp.write('\n'.join(['<!--', 1.88 + ofp.write('\n'.join(['\n<!--', 1.89 'local variables: ', 1.90 'sgml-parent-document: ("00book.xml" "book" "chapter")', 1.91 'end:',