Yuya Nishihara avatar Yuya Nishihara committed 9a4d64c

plantuml: add experimental support for rst2pdf

Comments (0)

Files changed (2)

plantuml/sphinxcontrib/plantuml.py

     self.body.append('\n\\includegraphics{%s}\n' % self.encode(refname))
     raise nodes.SkipNode
 
+def pdf_visit_plantuml(self, node):
+    try:
+        refname, outfname = render_plantuml(self, node, 'eps')
+        refname, outfname = _convert_eps_to_pdf(self, refname, outfname)
+    except PlantUmlError, err:
+        self.builder.warn(str(err))
+        raise nodes.SkipNode
+    rep = nodes.image(uri=outfname, alt=node['alt'] or node['uml'])
+    node.parent.replace(node, rep)
+
 def setup(app):
     app.add_node(plantuml,
                  html=(html_visit_plantuml, None),
     app.add_config_value('plantuml_output_format', 'png', 'html')
     app.add_config_value('plantuml_epstopdf', 'epstopdf', '')
     app.add_config_value('plantuml_latex_output_format', 'png', '')
+
+    # imitate what app.add_node() does
+    if 'rst2pdf.pdfbuilder' in app.config.extensions:
+        from rst2pdf.pdfbuilder import PDFTranslator as translator
+        setattr(translator, 'visit_' + plantuml.__name__, pdf_visit_plantuml)

plantuml/tests/test_functional.py

     assert_equals('Hello', epscontent[1])
     pdfcontent = readfile(pdffiles[0]).splitlines()
     assert os.path.basename(epsfiles[0]) in pdfcontent[0]
+
+@with_runsphinx('pdf')
+def test_buildpdf_simple():
+    """Generate simple PDF
+
+    .. uml::
+
+       Hello
+    """
+    epsfiles = glob.glob(os.path.join(_outdir, 'plantuml-*.eps'))
+    pdffiles = glob.glob(os.path.join(_outdir, 'plantuml-*.pdf'))
+    assert len(epsfiles) == 1
+    assert len(pdffiles) == 1
+
+    epscontent = readfile(epsfiles[0]).splitlines()
+    assert '-teps' in epscontent[0]
+    assert_equals('Hello', epscontent[1])
+    pdfcontent = readfile(pdffiles[0]).splitlines()
+    assert os.path.basename(epsfiles[0]) in pdfcontent[0]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.