]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mpl/doc/src/docutils/writers/html4_refdoc/__init__.py
2 # Copyright Aleksey Gurtovoy 2004-2009
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE_1_0.txt or copy at
6 # http://www.boost.org/LICENSE_1_0.txt)
8 from docutils
.writers
import html4_frames
9 from docutils
.writers
import html4css1
10 from docutils
import nodes
16 class Writer(html4_frames
.Writer
):
19 self
.__super
= html4_frames
.Writer
20 self
.__super
.__init
__(self
)
21 self
.translator
= refdoc_translator
24 class refdoc_translator(html4_frames
.frame_pages_translator
):
27 re_include
= re
.compile(r
'(\s*#include\s+<)(.*?\.hpp)?(>\s*)?')
28 re_identifier
= re
.compile(r
'(.*?\W*)(\w+)(\W.*?)?')
29 re_modtime
= re
.compile(r
'\s*modtime:\s*(.*)')
30 re_auto_id
= re
.compile(r
'^id(\d+)$')
34 def __init__(self
, document
, index_page
, page_files_dir
, extension
):
35 self
.docframe
+= ' refmanual'
36 self
.__super
= html4_frames
.frame_pages_translator
37 self
.__super
.__init
__(self
, document
, index_page
, page_files_dir
, extension
)
40 def visit_section( self
, node
):
42 self
= self
.active_visitor()
43 if self
.section_level
== 1:
44 self
.section_level
= 2
45 base
.__super
.visit_section( base
, node
)
47 def depart_section( self
, node
):
48 self
.__super
.depart_section( self
, node
)
49 self
= self
.active_visitor()
50 if self
.section_level
== 2:
51 self
.section_level
= 1
54 def visit_title( self
, node
):
55 self
.__super
.visit_title( self
, node
)
56 if self
.re_auto_id
.match( self
._node
_id
( node
.parent
) ):
57 name
= nodes
.make_id( node
.astext() )
58 self
= self
.active_visitor()
59 self
.body
.append( self
.starttag(
60 {}, 'a', '', name
=name
, href
='#%s' % name
, CLASS
='subsection-title'
63 def depart_title( self
, node
):
65 if self
.re_auto_id
.match( self
._node
_id
( node
.parent
) ):
66 self
= self
.active_visitor()
67 self
.body
.append( '</a>')
69 base
.__super
.depart_title( base
, node
)
72 def visit_table(self
, node
):
73 self
= self
.active_visitor()
75 self
.starttag(node
, 'table', CLASS
='docutils table', border
="1"))
78 def visit_reference(self
, node
):
80 if len(node
) == 1 and isinstance(node
[0], nodes
.literal
) and node
[0].has_key('class'):
81 if node
.has_key('class') and node
['class'].find(node
[0]['class']) == -1:
82 node
['class'] += ' %s' % node
[0]['class']
84 node
['class'] = node
[0]['class']
86 self
.__super
.visit_reference(self
, node
)
89 def depart_reference(self
, node
):
90 self
.__super
.depart_reference(self
, node
)
94 def visit_literal(self
, node
):
96 self
.__super
.visit_literal(self
, node
)
99 self
= self
.active_visitor()
101 self
.body
.append(self
.starttag(node
, 'tt', '', CLASS
='literal'))
104 if base
.re_include
.search(text
):
105 text
= base
.re_include
.sub(lambda m
: base
._handle
_include
_sub
(self
, m
), text
)
106 self
.body
.append('<span class="pre">%s</span>' % text
)
108 for token
in self
.words_and_spaces
.findall(text
):
110 if base
.re_identifier
.search(token
):
111 token
= base
.re_identifier
.sub(lambda m
: base
._handle
_id
_sub
(self
, m
), token
)
113 token
= self
.encode(token
)
115 self
.body
.append('<span class="pre">%s</span>' % token
)
116 elif token
in ('\n', ' '):
117 # Allow breaks at whitespace:
118 self
.body
.append(token
)
120 # Protect runs of multiple spaces; the last space can wrap:
121 self
.body
.append(' ' * (len(token
) - 1) + ' ')
123 self
.body
.append('</tt>')
124 # Content already processed:
128 def visit_literal_block(self
, node
):
129 self
.__super
.visit_literal_block(self
, node
)
130 self
.in_literal_block
= True
132 def depart_literal_block(self
, node
):
133 self
.__super
.depart_literal_block(self
, node
)
134 self
.in_literal_block
= False
137 def visit_license_and_copyright(self
, node
):
138 self
= self
.active_visitor()
139 self
.context
.append( len( self
.body
) )
141 def depart_license_and_copyright(self
, node
):
142 self
= self
.active_visitor()
143 start
= self
.context
.pop()
144 self
.footer
= self
.body
[start
:]
145 del self
.body
[start
:]
148 def visit_Text(self
, node
):
149 if not self
.in_literal_block
:
150 self
.__super
.visit_Text(self
, node
)
153 self
= self
.active_visitor()
156 if base
.re_include
.search(text
):
157 text
= base
.re_include
.sub(lambda m
: base
._handle
_include
_sub
(self
, m
), text
)
158 elif base
.re_identifier
.search(text
):
159 text
= base
.re_identifier
.sub(lambda m
: base
._handle
_id
_sub
(self
, m
), text
)
161 text
= self
.encode(text
)
163 self
.body
.append(text
)
166 def depart_Text(self
, node
):
170 def visit_substitution_reference(self
, node
):
172 print 'Unresolved substitution_reference:', node
.astext()
176 def _footer_content(self
):
177 self
= self
.active_visitor()
178 parts
= ''.join( self
.footer
).split( '\n' )
179 parts
= [ '<div class="copyright">%s</div>' % x
if x
.startswith( 'Copyright' ) else x
for x
in parts
]
180 return '<td><div class="copyright-footer">%s</div></td>' % '\n'.join( parts
) if len( parts
) else ''
183 def _toc_as_text( self
, visitor
):
184 footer_end
= visitor
.body
.pop()
185 visitor
.body
.append( self
._footer
_content
() )
186 visitor
.body
.append( footer_end
)
187 return visitor
.astext()
190 def _handle_include_sub(base
, self
, match
):
191 if not match
.group(2) or not match
.group():
192 return self
.encode(match
.group(0))
194 header
= match
.group(2)
195 result
= self
.encode(match
.group(1))
196 result
+= '<a href="%s" class="header">%s</a>' \
197 % ( '../../../../%s' % header
198 , self
.encode(header
)
201 result
+= self
.encode(match
.group(3))
205 def _handle_id_sub(base
, self
, match
):
206 identifier
= match
.group(2)
208 if not base
.document
.has_name( identifier
.lower() ):
209 return self
.encode(match
.group(0))
211 def get_section_id( id ):
212 node
= base
.document
.ids
[ id ]
213 if isinstance( node
, nodes
.section
):
216 if isinstance( node
, nodes
.target
):
217 return get_section_id( node
.get( 'refid' ) )
221 id = get_section_id( base
.document
.nameids
[ identifier
.lower() ] )
223 return self
.encode(match
.group(0))
226 id = 'inserter-class'
228 result
= self
.encode(match
.group(1))
229 result
+= '<a href="%s" class="identifier">%s</a>' \
230 % ( base
._chunk
_ref
( base
._active
_chunk
_id
(), base
._make
_chunk
_id
( id ) )
231 , self
.encode(identifier
)
235 result
+= self
.encode(match
.group(3))
240 def _make_chunk_id( self
, node_id
):
241 if self
.re_auto_id
.match( node_id
):
242 node
= self
.document
.ids
[ node_id
]
243 return '%s-%s' % ( self
._node
_id
( node
.parent
), node
['dupnames'][0] )
245 if node_id
.startswith( 'boost-mpl-' ):
246 return node_id
[ len( 'boost-mpl-' ): ]