+class HTMLMarkup (object):
+ def entity (self, name, string='', attributes=[]):
+ attr_list = ''.join ([' %s="%s"' % x for x in attributes])
+ return '<%(name)s%(attr_list)s>%(string)s</%(name)s>' % locals ()
+ def paragraph (self, string=''):
+ return self.entity ('p', string)
+ def table (self, string):
+ return self.entity ('table', string, [('align', 'center'), ('border', '2')])
+ def row (self, string, attributes=[]):
+ return self.entity ('tr', string, attributes)
+ headrow = row
+ def headcell (self, string, attributes=[]):
+ return self.entity ('th', string, attributes)
+ def cell (self, string='', attributes=[]):
+ return self.entity ('td', string, attributes)
+ def newline (self, attributes=[]):
+ return self.entity ('br', '', attributes)[:-5]
+ def span (self, string, attributes=[]):
+ return self.entity ('span', string, attributes)
+ def small (self, string, attributes=[]):
+ return self.entity ('small', string, attributes)
+ def emph (self, string, attributes=[]):
+ return self.entity ('em', string, attributes)
+
+class TexiMarkup (HTMLMarkup):
+ def entity (self, name, string='', attributes=[]):
+ return '''
+@%(name)s
+%(string)s
+@end %(name)s''' % locals ()
+ def paragraph (self, string=''):
+ return '''
+%(string)s''' % locals ()
+ def table (self, string):
+ # Ugh, makeinfo is fine without @columnfractions
+ # but texi2html 1.82 barfs: `empty multicolumn'
+ return (self.entity ('multitable', string)
+ .replace ('@multitable',
+ '@multitable @columnfractions' + ' .1' * 10))
+ def headrow (self, string, attributes=[]):
+ return '''
+@headitem ''' + string
+ def row (self, string, attributes=[]):
+ return '''
+@item ''' + string
+ def cell (self, string='', attributes=[]):
+ return '''
+@tab ''' + string
+ headcell = cell
+ def newline (self):
+ return ''' @*
+'''
+ def html (self, string):
+ return self.entity ('ifhtml', self.entity ('html', string))
+ def span (self, string, attributes=[]):
+ return self.html (HTMLMarkup ().span (string, attributes))
+ def small (self, string, attributes=[]):
+ return self.html (HTMLMarkup ().small (string, attributes))
+ def command (self, name, string):
+ return '@%(name)s{%(string)s}' % locals ()
+ def emph (self, string, attributes=[]):
+ return self.command ('emph', string)