From d0262994e2613890361cf8f3bf0a8fdfef85fe80 Mon Sep 17 00:00:00 2001 From: juergen Date: Mon, 16 Oct 2017 19:06:19 -0400 Subject: [PATCH 1/3] fix pweave -f sphinx and pweave -f rst not adding figure name/label to output file #88 --- pweave/formatters/rst.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pweave/formatters/rst.py b/pweave/formatters/rst.py index 4c7bb67..e296e25 100644 --- a/pweave/formatters/rst.py +++ b/pweave/formatters/rst.py @@ -14,6 +14,7 @@ def initformat(self): figfmt='.png', extension='rst', width='15 cm', + label='label', doctype='rst') self.fig_mimetypes = ["image/png", "image/jpg"] self.mimetypes = ["text/restructuredtext"] @@ -22,23 +23,24 @@ def initformat(self): def formatfigure(self, chunk): fignames = chunk['figure'] caption = chunk['caption'] + label = chunk['label'] width = chunk['width'] result = "" figstring = "" for fig in fignames: - figstring += ('.. image:: %s\n :width: %s\n\n' % (fig, width)) + figstring += ('.. image:: %s\n :name: %s\n :width: %s\n\n' % (fig, label, width)) if chunk['caption']: + # Maybe an additional option for 'label' in code chunk could be added as well? result += (".. figure:: %s\n" + " :name: %s\n" " :width: %s\n\n" - " %s\n\n" % (fignames[0], width, caption)) + " %s\n\n" % (fignames[0], label, width, caption)) else: result += figstring return result - - def _indent(self, text): """Indent blocks for formats where indent is significant""" if not text.startswith("\n"): @@ -64,6 +66,7 @@ def initformat(self): figfmt='.*', savedformats=['.png', '.pdf'], extension='rst', + label='label', width='15 cm', doctype='rst') self.fig_mimetypes = ["image/png", "image/jpg"] @@ -73,17 +76,21 @@ def initformat(self): def formatfigure(self, chunk): fignames = chunk['figure'] caption = chunk['caption'] + label = chunk['label'] width = chunk['width'] result = "" figstring = "" + for fig in fignames: - figstring += ('.. image:: %s\n :width: %s\n\n' % (fig, width)) + figstring += ('.. image:: %s\n :name: %s\n :width: %s\n\n' % (fig, label, width)) if chunk['caption']: - result += (".. figure:: %s\n" \ - " :width: %s\n\n" \ - " %s\n\n" % (fignames[0], width, caption)) + # Maybe an additional option for 'label' in code chunk could be added as well? + result += (".. figure:: %s\n" + " :name: %s\n" + " :width: %s\n\n" + " %s\n\n" % (fignames[0], label, width, caption)) else: result += figstring return result From 59cf07ad4614b95803d35b4b75f18c118f5144f3 Mon Sep 17 00:00:00 2001 From: juejung Date: Mon, 16 Oct 2017 19:15:29 -0400 Subject: [PATCH 2/3] fix pweave -f sphinx and pweave -f rst not adding figure name/label to output file #88 --- pweave/formatters/rst.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pweave/formatters/rst.py b/pweave/formatters/rst.py index e296e25..1adf3fd 100644 --- a/pweave/formatters/rst.py +++ b/pweave/formatters/rst.py @@ -32,7 +32,6 @@ def formatfigure(self, chunk): figstring += ('.. image:: %s\n :name: %s\n :width: %s\n\n' % (fig, label, width)) if chunk['caption']: - # Maybe an additional option for 'label' in code chunk could be added as well? result += (".. figure:: %s\n" " :name: %s\n" " :width: %s\n\n" @@ -86,7 +85,6 @@ def formatfigure(self, chunk): figstring += ('.. image:: %s\n :name: %s\n :width: %s\n\n' % (fig, label, width)) if chunk['caption']: - # Maybe an additional option for 'label' in code chunk could be added as well? result += (".. figure:: %s\n" " :name: %s\n" " :width: %s\n\n" From 8561d8cf38ae9154b448ede90564d502d3eef364 Mon Sep 17 00:00:00 2001 From: juejung Date: Mon, 16 Oct 2017 19:16:50 -0400 Subject: [PATCH 3/3] fix pweave -f sphinx and pweave -f rst not adding figure name/label to output file #88 --- pweave/formatters/rst.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pweave/formatters/rst.py b/pweave/formatters/rst.py index 1adf3fd..b2857a4 100644 --- a/pweave/formatters/rst.py +++ b/pweave/formatters/rst.py @@ -80,7 +80,6 @@ def formatfigure(self, chunk): result = "" figstring = "" - for fig in fignames: figstring += ('.. image:: %s\n :name: %s\n :width: %s\n\n' % (fig, label, width))