# fig
############################################################################
+class captitle(nodes.Part, nodes.TextElement):
+ pass
+
+def latex_visit_captitle(self, node):
+ self.body.append('\\caption[')
+
+def latex_depart_captitle(self, node):
+ self.body.append(']')
+
+class capdesc(nodes.Part, nodes.TextElement):
+ pass
+
+def latex_visit_capdesc(self, node):
+ self.body.append('{')
+
+def latex_depart_capdesc(self, node):
+ self.body.append('}\n')
+
class pad(nodes.Part, nodes.TextElement):
pass
fig_node['label'] = self.arguments[0]
node = nodes.Element() # anonymous container for parsing
self.state.nested_parse(self.content, self.content_offset, node)
- first_node = node[0]
- cap = None
- if isinstance(first_node, nodes.paragraph):
- cap = nodes.caption(first_node.rawsource, '', *first_node.children)
+ first_node = None
+ second_node = None
+ try:
+ first_node = node[0]
+ second_node = node[1]
+ except IndexError:
+ pass
+ is_first_para = isinstance(first_node, nodes.paragraph)
+ is_second_para = isinstance(second_node, nodes.paragraph)
+ capt = None
+ capd = None
+ if is_first_para and is_second_para:
+ capt = captitle(first_node.rawsource, '', *first_node.children)
+ capd = capdesc(second_node.rawsource, '', *second_node.children)
+ node = node[2:]
+ elif is_first_para:
+ capt = captitle(first_node.rawsource, '', *first_node.children)
+ capd = capdesc(first_node.rawsource, '', *first_node.children)
+ node = node[1:]
+ elif is_second_para:
+ capt = captitle(second_node.rawsource, '', *second_node.children)
+ capd = capdesc(second_node.rawsource, '', *second_node.children)
node = node[1:]
first = True
children = []
inches=fig_node['padding']))
children.append(n)
fig_node += children
- if cap:
- fig_node += cap
+ if capt and capd:
+ fig_node += capt
+ fig_node += capd
return [fig_node]
def setup(app):
app.add_node(subcap, latex=(latex_visit_subcap, latex_depart_subcap))
app.add_node(subfig, latex=(latex_visit_subfig, latex_depart_subfig))
+ app.add_node(captitle, latex=(latex_visit_captitle, latex_depart_captitle))
+ app.add_node(capdesc, latex=(latex_visit_capdesc, latex_depart_capdesc))
app.add_node(pad, latex=(latex_visit_pad, latex_depart_pad))
app.add_node(fig, latex=(latex_visit_fig, latex_depart_fig))
app.add_directive('fig', FigDirective)