Exemple #1
0
 def __init__(self, lyx, outcb=None, debugcb=None, debug_level=0):
     self.app_debugcb = debugcb
     self.debug_level = debug_level
     if debugcb:
         self.dbg = self._debugcb
     else:
         self.dbg = self._null_debugcb
     self.stack = []
     self.i = 0
     if type(lyx) == list:
         self.lines = lyx
     elif type(lyx) == str:
         self.lines = _read_lyx(lyx)
     else:
         assert lyx.readlines
         self.lines = lyx.readlines()
     self.xout = XmlStreamer(outcb or LyX2XML._outcb, 'lyx')  # No DTD...
     # XXX Should move the rest of this to a 'convert' method.
     #
     # Fix the lack of XML-ish nesting of things like \series, \emph,
     # \family, \color, \shape, and \lang
     self._fix_text_styling()
     # Uncomment to save a copy of the .lyx with fixed styling, for
     # debugging purposes:
     #f = open('/tmp/f', 'w+')
     #for i in range(len(self.lines)):
     #    f.write(self.lines[i])
     #    if self.lines[i][-1] != '\n':
     #        f.write('\n')
     #f.close()
     if self.debug_level >= 3:
         self.dbg(3, 'Fixed lines:\n')
         for i in range(len(self.lines)):
             self.dbg(3, '%d %s' % (i + 1, self.lines[i]))
     self._lyx2xml()
     self.xout.finish()
     return None