Added the ability to insert a page break when a ".. page break" comment is

inserted in a ReST text.

For the moment, works only before paragraphs, lists, list items and sections.

authorOlivier CAYROL (Logilab) <Olivier.Cayrol@logilab.fr>
changeset6af47c546dc2
branchdefault
phasepublic
hiddenno
parent revision#c6d0dabafc9a Added tag logilab-doctools-debian-version-0.3.0-1 for changeset 888c2359e294
child revision#a3cece728832 fix makeindex being called at the wrong moment with wrong arguments (closes: #82702)
files modified by this revision
rest_docbook.py
# HG changeset patch
# User Olivier CAYROL (Logilab) <Olivier.Cayrol@logilab.fr>
# Date 1316092832 -7200
# Thu Sep 15 15:20:32 2011 +0200
# Node ID 6af47c546dc2b7289baa596556a89e4b96fe7c6d
# Parent c6d0dabafc9ae9a6cb1de25b696ee4c8a1f99922
Added the ability to insert a page break when a ".. page break" comment is
inserted in a ReST text.

For the moment, works only before paragraphs, lists, list items and sections.

diff --git a/rest_docbook.py b/rest_docbook.py
@@ -195,10 +195,11 @@
1          self.context = []
2          self.footnotes = {}
3          self.footnote_map = {}
4          self.docinfo = []
5          self.insert_in_docinfo = False
6 +        self.insert_page_break= False
7          self.in_generated_node = False
8          self.in_section_title = False
9          self.high_level_elt_type = None
10          self.colnames = []
11          self.single_para_in_entry = False
@@ -313,14 +314,18 @@
12 
13      def depart_block_quote(self, node):
14          self.body.append('</blockquote>\n')
15 
16      def visit_bullet_list(self, node):
17 +        attribs = {}
18 +        if self.insert_page_break:
19 +            attribs["ldg:break"] = "page"
20 +            self.insert_page_break = False
21          if self.insert_in_docinfo:
22 -            self.docinfo.append(self.starttag(node, 'itemizedlist'))
23 +            self.docinfo.append(self.starttag(node, 'itemizedlist', **attribs))
24          else:
25 -            self.body.append(self.starttag(node, 'itemizedlist'))
26 +            self.body.append(self.starttag(node, 'itemizedlist', **attribs))
27 
28      def depart_bullet_list(self, node):
29          if self.insert_in_docinfo:
30              self.docinfo.append('</itemizedlist>\n')
31          else:
@@ -406,10 +411,12 @@
32          """Escape double-dashes in comment text."""
33          if self.insert_in_docinfo:
34              self.docinfo.append('<!-- %s -->\n' % sub('- ', node.astext()))
35          else:
36              self.body.append('<!-- %s -->\n' % sub('- ', node.astext()))
37 +        if node.astext() == "page break":
38 +            self.insert_page_break = True
39          raise nodes.SkipNode
40 
41      # contact is handled in ``visit_docinfo()``
42      def visit_contact(self, node):
43          raise nodes.SkipNode
@@ -631,10 +638,13 @@
44      def visit_enumerated_list(self, node):
45          # TODO: need to specify "mark" type used for list items
46          atts = {}
47          if node.has_key('start'):
48              atts['ldg:first-number'] = node['start']
49 +        if self.insert_page_break:
50 +            atts["ldg:break"] = "page"
51 +            self.insert_page_break = False
52          if self.insert_in_docinfo:
53              self.docinfo.append(self.starttag(node, 'orderedlist', **atts))
54          else:
55              self.body.append(self.starttag(node, 'orderedlist', **atts))
56 
@@ -869,14 +879,18 @@
57 
58      def depart_line_block(self, node):
59          self.body.append('</literallayout>\n')
60 
61      def visit_list_item(self, node):
62 +        attribs = {}
63 +        if self.insert_page_break:
64 +            attribs["ldg:break"] = "page"
65 +            self.insert_page_break = False
66          if self.insert_in_docinfo:
67 -            self.docinfo.append(self.starttag(node, 'listitem'))
68 +            self.docinfo.append(self.starttag(node, 'listitem', **attribs))
69          else:
70 -            self.body.append(self.starttag(node, 'listitem'))
71 +            self.body.append(self.starttag(node, 'listitem', **attribs))
72 
73      def depart_list_item(self, node):
74          if self.insert_in_docinfo:
75              self.docinfo.append('</listitem>\n')
76          else:
@@ -966,12 +980,13 @@
77              attribs = {}
78              if len(node['ids']) > 0:
79                  id_para = node['ids'][-1]
80              else:
81                  id_para = None
82 -            if node.get('pagebreak','') == "true":
83 +            if node.get('pagebreak','') == "true" or self.insert_page_break:
84                  attribs["ldg:break"] = "page"
85 +                self.insert_page_break = False
86              if self.insert_in_docinfo:
87                  self.docinfo.append(self.starttag(node, 'para', '', id=id_para,
88                                                    **attribs))
89              else:
90                  self.body.append(self.starttag(node, 'para', '', id=id_para,
@@ -1027,30 +1042,38 @@
91 
92      def depart_row(self, node):
93          self.body.append('</row>\n')
94 
95      def visit_section(self, node):
96 +        attribs = {}
97          if len(node['ids']) > 0:
98              id_sect = node['ids'][-1]
99          else:
100              id_sect = None
101 -        if len(node['classes']) > 0:
102 -            class_sect = node ['classes'][-1]
103 +        if 'appendix' in node['classes']:
104 +            node['classes'].remove('appendix')
105 +            level0_name = 'appendix'
106          else:
107 -            class_sect = None
108 +            level0_name = 'chapter'
109 +        if self.insert_page_break:
110 +            attribs["ldg:break"] = "page"
111 +            self.insert_page_break = False
112 +        if len(node['classes']) > 0:
113 +            attribs['role'] = node ['classes'][-1]
114          if self.section == 0 and self.doctype == 'book':
115 -            self.body.append(self.starttag(node, 'chapter', id=id_sect, 
116 -                                           role=class_sect))
117 +            self.body.append(self.starttag(node, level0_name, id=id_sect, 
118 +                                           **attribs))
119 +            self.context.append(level0_name)
120          else:
121              self.body.append(self.starttag(node, 'section', id=id_sect,
122 -                                           role=class_sect))
123 +                                           **attribs))
124          self.section += 1
125 
126      def depart_section(self, node):
127          self.section -= 1
128          if self.section == 0 and self.doctype == 'book':
129 -            self.body.append('</chapter>\n')
130 +            self.body.append('</%s>\n' % self.context.pop())
131          else:
132              self.body.append('</section>\n')
133 
134      def visit_sidebar(self, node):
135          self.body.append(self.starttag(node, 'sidebar'))
@@ -1099,17 +1122,21 @@
136 
137      # TODO: system_message
138      visit_system_message = depart_system_message = lambda self, node: None
139 
140      def visit_table(self, node):
141 +        attribs = {}
142          title_node = [n for n in node if isinstance(n,nodes.title)]
143          if title_node:
144              self.high_level_elt_type = 'table'
145          else:
146              self.high_level_elt_type = 'informaltable'
147 +        if self.insert_page_break:
148 +            attribs["ldg:break"] = "page"
149 +            self.insert_page_break = False
150          self.body.append(
151 -            self.starttag(node, self.high_level_elt_type, frame='all')
152 +           self.starttag(node, self.high_level_elt_type, frame='all', **attribs)
153          )
154 
155      def depart_table(self, node):
156          self.body.append('</%s>\n' % self.high_level_elt_type)
157          self.high_level_elt_type = None