Commits

Olivier Heurtier committed 94411f5

plantuml: support caption definition

  • Participants
  • Parent commits 283a0cf

Comments (0)

Files changed (5)

File plantuml/README.rst

 
        Foo <|-- Bar
 
+You can specify a caption::
+
+    .. uml::
+       :caption: Caption with **bold** and *italic*
+       :width: 50mm
+
+       Foo <|-- Bar
+
 For details, please see PlantUML_ documentation.
 
 .. _PlantUML: http://plantuml.sourceforge.net/

File plantuml/sphinxcontrib/plantuml.py

     """
     has_content = True
     option_spec = {'alt': directives.unchanged,
+                   'caption': directives.unchanged,
                    # TODO: process the following options by html writer
                    'height': directives.length_or_unitless,
                    'width': directives.length_or_percentage_or_unitless,
     def run(self):
         node = plantuml(self.block_text, **self.options)
         node['uml'] = '\n'.join(self.content)
+
+        # if a caption is defined, insert a 'figure' with this node and the caption
+        if 'caption' in self.options:
+            import docutils.statemachine
+            cnode = nodes.Element()          # anonymous container for parsing
+            sl = docutils.statemachine.StringList([self.options['caption']],source='')
+            self.state.nested_parse(sl,self.content_offset, cnode)
+            caption = nodes.caption(self.options['caption'], '', *cnode)
+            fig = nodes.figure('',node)
+            fig += caption
+            node = fig
         return [node]
 
 def generate_name(self, node, fileformat):

File plantuml/tests/fixture/index.rst

 Class diagram:
 
 .. uml::
+   :caption: A caption with **bold** text
 
    Foo <|-- Bar
 

File plantuml/tests/test_functional.py

     assert 'alt="Foo &lt;Bar&gt;"' in readfile('index.html')
 
 @with_runsphinx('html')
+def test_buildhtml_caption():
+    """Generate HTML with caption specified
+
+    .. uml::
+       :caption: Caption with **bold** and *italic*
+
+       Hello
+    """
+    assert 'Caption with <strong>bold</strong> and <em>italic</em>' in readfile('index.html')
+
+@with_runsphinx('html')
 def test_buildhtml_nonascii():
     u"""Generate simple HTML of non-ascii diagram
 

File plantuml/tox.ini

 [testenv:python]
 deps=
     ## if you use nose for test running
-    # nose
+    nose
     ## if you use py.test for test running
     # py
+    rst2pdf
 commands=
     ## run tests with py.test
     # py.test []
     ## run tests with nose
-    # nose
+    nosetests []
 
 [testenv:doc]
 deps=