<s> from cStringIO import StringIO <EOL> import os , re <EOL> from twisted . python import text <EOL> from twisted . web import domhelpers <EOL> import latex , tree <EOL> spaceRe = re . compile ( '<STR_LIT>' ) <EOL> def texiEscape ( text ) : <EOL> return spaceRe . sub ( text , '<STR_LIT:U+0020>' ) <EOL> entities = latex . entities . copy ( ) <EOL> entities [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> class TexiSpitter ( latex . BaseLatexSpitter ) : <EOL> baseLevel = <NUM_LIT:1> <EOL> def writeNodeData ( self , node ) : <EOL> buf = StringIO ( ) <EOL> latex . getLatexText ( node , self . writer , texiEscape , entities ) <EOL> def visitNode_title ( self , node ) : <EOL> self . writer ( '<STR_LIT>' ) <EOL> self . visitNodeDefault ( node ) <EOL> self . writer ( '<STR_LIT:\n>' ) <EOL> self . writer ( '<STR_LIT>' ) <EOL> self . visitNodeDefault ( node ) <EOL> self . writer ( '<STR_LIT:\n>' ) <EOL> headers = tree . getHeaders ( domhelpers . getParents ( node ) [ - <NUM_LIT:1> ] ) <EOL> if not headers : <EOL> return <EOL> self . writer ( '<STR_LIT>' ) <EOL> for header in headers : <EOL> self . writer ( '<STR_LIT>' % domhelpers . getNodeText ( header ) ) <EOL> self . writer ( '<STR_LIT>' ) <EOL> def visitNode_pre ( self , node ) : <EOL> self . writer ( '<STR_LIT>' ) <EOL> buf = StringIO ( ) <EOL> latex . getLatexText ( node , buf . write , entities = entities ) <EOL> self . writer ( text . removeLeadingTrailingBlanks ( buf . getvalue ( ) ) ) <EOL> self . writer ( '<STR_LIT>' ) <EOL> def visitNode_code ( self , node ) : <EOL> fout = StringIO ( ) <EOL> latex . getLatexText ( node , fout . write , texiEscape , entities ) <EOL> self . writer ( '<STR_LIT>' + fout . getvalue ( ) + '<STR_LIT:}>' ) <EOL> def visitNodeHeader ( self , node ) : <EOL> self . writer ( '<STR_LIT>' ) <EOL> self . visitNodeDefault ( node ) <EOL> self . writer ( '<STR_LIT:\n>' ) <EOL> level = ( int ( node . tagName [ <NUM_LIT:1> ] ) - <NUM_LIT:2> ) + self . baseLevel <EOL> self . writer ( '<STR_LIT>' + level * '<STR_LIT>' + '<STR_LIT>' ) <EOL> self . visitNodeDefault ( node ) <EOL> self . writer ( '<STR_LIT:\n>' ) <EOL> def visitNode_a_listing ( self , node ) : <EOL> fileName = os . path . join ( self . currDir , node . getAttribute ( '<STR_LIT>' ) ) <EOL> self . writer ( '<STR_LIT>' ) <EOL> self . writer ( open ( fileName ) . read ( ) ) <EOL> self . writer ( '<STR_LIT>' ) <EOL> def visitNode_a_href ( self , node ) : <EOL> self . visitNodeDefault ( node ) <EOL> def visitNode_a_name ( self , node ) : <EOL> self . visitNodeDefault ( node ) <EOL> visitNode_h2 = visitNode_h3 = visitNode_h4 = visitNodeHeader <EOL> start_dl = '<STR_LIT>' <EOL> end_dl = '<STR_LIT>' <EOL> start_ul = '<STR_LIT>' <EOL> end_ul = '<STR_LIT>' <EOL> start_ol = '<STR_LIT>' <EOL> end_ol = '<STR_LIT>' <EOL> start_li = '<STR_LIT>' <EOL> end_li = '<STR_LIT:\n>' <EOL> start_dt = '<STR_LIT>' <EOL> end_dt = '<STR_LIT>' <EOL> end_dd = '<STR_LIT:\n>' <EOL> start_p = '<STR_LIT>' <EOL> start_strong = start_em = '<STR_LIT>' <EOL> end_strong = end_em = '<STR_LIT:}>' <EOL> start_q = "<STR_LIT>" <EOL> end_q = "<STR_LIT>" <EOL> start_span_footnote = '<STR_LIT>' <EOL> end_span_footnote = '<STR_LIT:}>' <EOL> start_div_note = '<STR_LIT>' <EOL> end_div_note = '<STR_LIT>' <EOL> start_th = '<STR_LIT>' <EOL> end_th = '<STR_LIT:}>' </s>
