1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 DocBook output support for Lore.
9 from xml.dom import minidom as dom
11 from twisted.lore import latex
14 class DocbookSpitter(latex.BaseLatexSpitter):
18 def writeNodeData(self, node):
19 self.writer(node.data)
21 def visitNode_body(self, node):
22 self.visitNodeDefault(node)
23 self.writer('</section>'*self.currentLevel)
25 def visitNodeHeader(self, node):
26 level = int(node.tagName[1])
27 difference, self.currentLevel = level-self.currentLevel, level
28 self.writer('<section>'*difference+'</section>'*-difference)
30 self.writer('</section>\n<section>')
31 self.writer('<title>')
32 self.visitNodeDefault(node)
34 def visitNode_a_listing(self, node):
35 fileName = os.path.join(self.currDir, node.getAttribute('href'))
36 self.writer('<programlisting>\n')
37 self.writer(cgi.escape(open(fileName).read()))
38 self.writer('</programlisting>\n')
40 def visitNode_a_href(self, node):
41 self.visitNodeDefault(node)
43 def visitNode_a_name(self, node):
44 self.visitNodeDefault(node)
46 def visitNode_li(self, node):
47 for child in node.childNodes:
48 if getattr(child, 'tagName', None) != 'p':
49 new = dom.Element('p')
50 new.childNodes = [child]
51 node.replaceChild(new, child)
52 self.visitNodeDefault(node)
54 visitNode_h2 = visitNode_h3 = visitNode_h4 = visitNodeHeader
55 end_h2 = end_h3 = end_h4 = '</title><para />'
56 start_title, end_title = '<section><title>', '</title><para />'
57 start_p, end_p = '<para>', '</para>'
58 start_strong, end_strong = start_em, end_em = '<emphasis>', '</emphasis>'
59 start_span_footnote, end_span_footnote = '<footnote><para>', '</para></footnote>'
61 start_pre, end_pre = '<programlisting>', '</programlisting>'
62 start_div_note, end_div_note = '<note>', '</note>'
63 start_li, end_li = '<listitem>', '</listitem>'
64 start_ul, end_ul = '<itemizedlist>', '</itemizedlist>'
65 start_ol, end_ol = '<orderedlist>', '</orderedlist>'
66 start_dl, end_dl = '<variablelist>', '</variablelist>'
67 start_dt, end_dt = '<varlistentry><term>', '</term>'
68 start_dd, end_dd = '<listitem><para>', '</para></listitem></varlistentry>'