From 4d34120eb81a0297ea2629531ddb522617345af8 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sun, 7 Jun 2009 13:26:29 -0300 Subject: [PATCH 1/1] =?utf8?q?Agregar=20soporte=20de=20t=C3=ADtulos=20a=20?= =?utf8?q?extensi=C3=B3n=20fig?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Las figuras pueden tener un título (utilizado en el índice de figuras) y una descripción. La extensión fig solo ponía la descripción. Este parche permite poner el título también, si la figura empieza con 2 párrafos el primero se interpreta como título y el segundo como descripción. --- ext/fig.py | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/ext/fig.py b/ext/fig.py index d258dea..ad24d18 100644 --- a/ext/fig.py +++ b/ext/fig.py @@ -67,6 +67,24 @@ class SubfigDirective(Directive): # 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 @@ -114,10 +132,28 @@ class FigDirective(Directive): 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 = [] @@ -130,8 +166,9 @@ class FigDirective(Directive): 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] @@ -139,6 +176,8 @@ class FigDirective(Directive): 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) -- 2.43.0