1 from docutils
import nodes
4 class InfoTranslator(nodes
.NodeVisitor
):
6 document_start
= """\\input texinfo @c -*-texinfo-*-
9 def __init__(self
, document
):
10 nodes
.NodeVisitor
.__init
__(self
, document
)
11 self
.settings
= document
.settings
14 self
.section_level
= 0
18 return '\n'.join(self
.header
+ self
.body
+ [''])
20 def visit_document(self
, node
):
21 self
.header
.append(self
.document_start
)
23 def depart_document(self
, node
):
26 def visit_comment(self
, node
):
27 self
.body
.append('@c %s' % node
.astext())
30 def visit_section(self
, node
):
31 self
.section_level
+= 1
32 #self.body.append('@c +s %d' % self.section_level)
34 def depart_section(self
, node
):
35 self
.section_level
-= 1
36 #self.body.append('@c -s %d' % self.section_level)
38 def emit_title(self
, text
):
39 self
.body
.append('@node Top')
40 self
.body
.append('@top %s' % text
)
42 def emit_chapter(self
, text
):
43 self
.body
.append('@chapter %s' % text
)
45 def emit_section(self
, text
):
46 self
.body
.append('@section %s' % text
)
48 def emit_subsection(self
, text
):
49 self
.body
.append('@subsection %s' % text
)
51 def visit_title(self
, node
):
52 title_functions
= [self
.emit_title
, self
.emit_chapter
, self
.emit_section
, self
.emit_subsection
]
54 f
= title_functions
[self
.section_level
]
55 except exceptions
.IndexError:
56 f
= self
.emit_subsection
57 #self.body.append('@c section_level %d' % self.section_level)
61 def visit_subtitle(self
, node
):
62 self
.body
.append('@majorheading %s' % node
.astext())
65 def visit_paragraph(self
, node
):
66 self
.body
.append(node
.astext())
69 def visit_bullet_list(self
, node
):
70 self
.body
.append('@itemize @bullet')
72 def depart_bullet_list(self
, node
):
73 self
.body
.append('@end @itemize')
75 def visit_list_item(self
, node
):
76 self
.body
.append('@item')
78 def depart_list_item(self
, node
):
81 def visit_literal(self
, node
):
84 def visit_literal_block(self
, node
):
85 self
.body
.append(node
.astext())
88 def visit_block_quote(self
, node
):
89 self
.body
.append('@quotation')
91 def depart_block_quote(self
, node
):
92 self
.body
.append('@end quotation')