comparison doc/rst2man.py @ 9712:18b134ef294c

kill trailing whitespace
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Thu, 05 Nov 2009 10:44:36 +0100
parents 816564f5dea9
children 8bba9157b30a
comparison
equal deleted inserted replaced
9711:d29bd00bbc50 9712:18b134ef294c
6 6
7 """ 7 """
8 Simple man page writer for reStructuredText. 8 Simple man page writer for reStructuredText.
9 9
10 Man pages (short for "manual pages") contain system documentation on unix-like 10 Man pages (short for "manual pages") contain system documentation on unix-like
11 systems. The pages are grouped in numbered sections: 11 systems. The pages are grouped in numbered sections:
12 12
13 1 executable programs and shell commands 13 1 executable programs and shell commands
14 2 system calls 14 2 system calls
15 3 library functions 15 3 library functions
16 4 special files 16 4 special files
138 text = ['.TS\n'] 138 text = ['.TS\n']
139 text.append(' '.join(self._options) + ';\n') 139 text.append(' '.join(self._options) + ';\n')
140 text.append('|%s|.\n' % ('|'.join(self._coldefs))) 140 text.append('|%s|.\n' % ('|'.join(self._coldefs)))
141 for row in self._rows: 141 for row in self._rows:
142 # row = array of cells. cell = array of lines. 142 # row = array of cells. cell = array of lines.
143 text.append('_\n') # line above 143 text.append('_\n') # line above
144 text.append('T{\n') 144 text.append('T{\n')
145 for i in range(len(row)): 145 for i in range(len(row)):
146 cell = row[i] 146 cell = row[i]
147 self._minimize_cell(cell) 147 self._minimize_cell(cell)
148 text.extend(cell) 148 text.extend(cell)
182 # docinfo. 182 # docinfo.
183 self._docinfo = { 183 self._docinfo = {
184 "title" : "", "title_upper": "", 184 "title" : "", "title_upper": "",
185 "subtitle" : "", 185 "subtitle" : "",
186 "manual_section" : "", "manual_group" : "", 186 "manual_section" : "", "manual_group" : "",
187 "author" : [], 187 "author" : [],
188 "date" : "", 188 "date" : "",
189 "copyright" : "", 189 "copyright" : "",
190 "version" : "", 190 "version" : "",
191 } 191 }
192 self._docinfo_keys = [] # a list to keep the sequence as in source. 192 self._docinfo_keys = [] # a list to keep the sequence as in source.
193 self._docinfo_names = {} # to get name from text not normalized. 193 self._docinfo_names = {} # to get name from text not normalized.
214 'field_name' : ('.TP\n.B ', '\n'), 214 'field_name' : ('.TP\n.B ', '\n'),
215 'literal' : ('\\fB', '\\fP'), 215 'literal' : ('\\fB', '\\fP'),
216 'literal_block' : ('.sp\n.nf\n.ft C\n', '\n.ft P\n.fi\n'), 216 'literal_block' : ('.sp\n.nf\n.ft C\n', '\n.ft P\n.fi\n'),
217 217
218 'option_list_item' : ('.TP\n', ''), 218 'option_list_item' : ('.TP\n', ''),
219 219
220 'reference' : (r'\%', r'\:'), 220 'reference' : (r'\%', r'\:'),
221 'emphasis': ('\\fI', '\\fP'), 221 'emphasis': ('\\fI', '\\fP'),
222 'strong' : ('\\fB', '\\fP'), 222 'strong' : ('\\fB', '\\fP'),
223 'term' : ('\n.B ', '\n'), 223 'term' : ('\n.B ', '\n'),
224 'title_reference' : ('\\fI', '\\fP'), 224 'title_reference' : ('\\fI', '\\fP'),
261 if self.body[i-1][:4] in ('.BI ','.IP '): 261 if self.body[i-1][:4] in ('.BI ','.IP '):
262 self.body[i] = '.\n' 262 self.body[i] = '.\n'
263 elif (self.body[i-1][:3] == '.B ' and 263 elif (self.body[i-1][:3] == '.B ' and
264 self.body[i-2][:4] == '.TP\n'): 264 self.body[i-2][:4] == '.TP\n'):
265 self.body[i] = '.\n' 265 self.body[i] = '.\n'
266 elif (self.body[i-1] == '\n' and 266 elif (self.body[i-1] == '\n' and
267 self.body[i-2][0] != '.' and 267 self.body[i-2][0] != '.' and
268 (self.body[i-3][:7] == '.TP\n.B ' 268 (self.body[i-3][:7] == '.TP\n.B '
269 or self.body[i-3][:4] == '\n.B ') 269 or self.body[i-3][:4] == '\n.B ')
270 ): 270 ):
271 self.body[i] = '.\n' 271 self.body[i] = '.\n'
562 # writing header is postboned 562 # writing header is postboned
563 self.header_written = 0 563 self.header_written = 0
564 564
565 def depart_document(self, node): 565 def depart_document(self, node):
566 if self._docinfo['author']: 566 if self._docinfo['author']:
567 self.body.append('.SH AUTHOR\n%s\n' 567 self.body.append('.SH AUTHOR\n%s\n'
568 % ', '.join(self._docinfo['author'])) 568 % ', '.join(self._docinfo['author']))
569 skip = ('author', 'copyright', 'date', 569 skip = ('author', 'copyright', 'date',
570 'manual_group', 'manual_section', 570 'manual_group', 'manual_section',
571 'subtitle', 571 'subtitle',
572 'title', 'title_upper', 'version') 572 'title', 'title_upper', 'version')
573 for name in self._docinfo_keys: 573 for name in self._docinfo_keys:
574 if name == 'address': 574 if name == 'address':
575 self.body.append("\n%s:\n%s%s.nf\n%s\n.fi\n%s%s" % ( 575 self.body.append("\n%s:\n%s%s.nf\n%s\n.fi\n%s%s" % (
585 label = self._docinfo_names[name] 585 label = self._docinfo_names[name]
586 else: 586 else:
587 label = self.language.labels.get(name, name) 587 label = self.language.labels.get(name, name)
588 self.body.append("\n%s: %s\n" % (label, self._docinfo[name]) ) 588 self.body.append("\n%s: %s\n" % (label, self._docinfo[name]) )
589 if self._docinfo['copyright']: 589 if self._docinfo['copyright']:
590 self.body.append('.SH COPYRIGHT\n%s\n' 590 self.body.append('.SH COPYRIGHT\n%s\n'
591 % self._docinfo['copyright']) 591 % self._docinfo['copyright'])
592 self.body.append( self.comment( 592 self.body.append( self.comment(
593 'Generated by docutils manpage writer.\n' ) ) 593 'Generated by docutils manpage writer.\n' ) )
594 594
595 def visit_emphasis(self, node): 595 def visit_emphasis(self, node):
894 pass 894 pass
895 895
896 def visit_paragraph(self, node): 896 def visit_paragraph(self, node):
897 # ``.PP`` : Start standard indented paragraph. 897 # ``.PP`` : Start standard indented paragraph.
898 # ``.LP`` : Start block paragraph, all except the first. 898 # ``.LP`` : Start block paragraph, all except the first.
899 # ``.P [type]`` : Start paragraph type. 899 # ``.P [type]`` : Start paragraph type.
900 # NOTE dont use paragraph starts because they reset indentation. 900 # NOTE dont use paragraph starts because they reset indentation.
901 # ``.sp`` is only vertical space 901 # ``.sp`` is only vertical space
902 self.ensure_eol() 902 self.ensure_eol()
903 self.body.append('.sp\n') 903 self.body.append('.sp\n')
904 904