# Twisted, the Framework of Your Internet
# Copyright (C) 2001-2002 Matthew W. Lefkowitz
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of version 2.1 of the GNU Lesser General Public
# License as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
from cStringIO import StringIO
import os, re, cgi
from twisted.python import text
from twisted.web import domhelpers, microdom
import latex, tree
class DocbookSpitter(latex.BaseLatexSpitter):
currentLevel = 1
def writeNodeData(self, node):
self.writer(node.data)
def visitNode_body(self, node):
self.visitNodeDefault(node)
self.writer(''*self.currentLevel)
def visitNodeHeader(self, node):
level = int(node.tagName[1])
difference, self.currentLevel = level-self.currentLevel, level
self.writer(''*-difference)
if difference<=0:
self.writer('\n')
self.writer('')
self.visitNodeDefault(node)
def visitNode_a_listing(self, node):
fileName = os.path.join(self.currDir, node.getAttribute('href'))
self.writer('\n')
self.writer(cgi.escape(open(fileName).read()))
self.writer('\n')
def visitNode_a_href(self, node):
self.visitNodeDefault(node)
def visitNode_a_name(self, node):
self.visitNodeDefault(node)
def visitNode_li(self, node):
for child in node.childNodes:
if getattr(child, 'tagName', None) != 'p':
new = microdom.Element('p')
new.childNodes = [child]
node.replaceChild(new, child)
self.visitNodeDefault(node)
visitNode_h2 = visitNode_h3 = visitNode_h4 = visitNodeHeader
end_h2 = end_h3 = end_h4 = ''
start_title, end_title = '', ''
start_p, end_p = '', ''
start_strong, end_strong = start_em, end_em = '', ''
start_span_footnote, end_span_footnote = '', ''
start_q = end_q = '"'
start_pre, end_pre = '', ''
start_div_note, end_div_note = '', ''
start_li, end_li = '', ''
start_ul, end_ul = '', ''
start_ol, end_ol = '', ''
start_dl, end_dl = '', ''
start_dt, end_dt = '', ''
start_dd, end_dd = '', ''