From db01d18c27d1e81548b748cd4527b3e891986219 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sat, 12 Apr 2014 12:16:56 -0700 Subject: [PATCH 1/3] Swap SVG `object` tags with `image` tags --- lib/github/commands/rest2html | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/github/commands/rest2html b/lib/github/commands/rest2html index eff55aa3..47ced6ec 100755 --- a/lib/github/commands/rest2html +++ b/lib/github/commands/rest2html @@ -28,6 +28,7 @@ __license__ = "CC0" __version__ = "0.1" import sys +import os # This fixes docutils failing with unicode parameters to CSV-Table. The -S # switch and the following 2 lines can be removed after upgrading to python 3. @@ -89,6 +90,27 @@ class GitHubHTMLTranslator(HTMLTranslator): def depart_table(self, node): self.body.append('\n') + def depart_image(self, node): + uri = node['uri'] + ext = os.path.splitext(uri)[1].lower() + # we need to swap RST's obj with img tags + # see http://git.io/5me3dA + if ext == ".svg": + # preserve essential attributes + atts = {} + atts['src'] = node['uri'] + atts['alt'] = node.get('alt', uri) + if 'width' in node: + atts['width'] = node['width'] + if 'height' in node: + atts['height'] = node['height'] + + # toss off obj tag + self.body.pop() + # add on img with attributes + self.body.append(self.starttag(node, 'img', **atts)) + self.body.append(self.context.pop()) + def main(): """ Parses the given ReST file or the redirected string input and returns the From f2f9917e1f50e8ee3188e6bdee2aea240a9b73f3 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sat, 12 Apr 2014 12:17:09 -0700 Subject: [PATCH 2/3] Add tests for swapping `object` tags with `image` tags --- test/markups/README.rst | 8 ++++++++ test/markups/README.rst.html | 3 +++ 2 files changed, 11 insertions(+) diff --git a/test/markups/README.rst b/test/markups/README.rst index e207534a..fd8ad722 100644 --- a/test/markups/README.rst +++ b/test/markups/README.rst @@ -33,3 +33,11 @@ API http://pullv.readthedocs.org/en/latest/api.html Issues https://github.com/tony/pullv/issues Source https://github.com/tony/pullv ============== ========================================================== + + +.. image:: https://scan.coverity.com/projects/621/badge.svg + :target: https://scan.coverity.com/projects/621 + :alt: Coverity Scan Build Status + +.. image:: https://scan.coverity.com/projects/621/badge.svg + :alt: Coverity Scan Build Status diff --git a/test/markups/README.rst.html b/test/markups/README.rst.html index 562a8e89..77990de5 100644 --- a/test/markups/README.rst.html +++ b/test/markups/README.rst.html @@ -49,3 +49,6 @@

Header 2

+Coverity Scan Build Status + +Coverity Scan Build Status From 7a9da183776cb85b19a56c86cbef1204649acc9b Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sat, 12 Apr 2014 15:12:08 -0700 Subject: [PATCH 3/3] Just pass along every attribute to the `ing` (except empty values) --- lib/github/commands/foo.rst | 7 +++++++ lib/github/commands/rest2html | 21 +++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 lib/github/commands/foo.rst diff --git a/lib/github/commands/foo.rst b/lib/github/commands/foo.rst new file mode 100644 index 00000000..e0950998 --- /dev/null +++ b/lib/github/commands/foo.rst @@ -0,0 +1,7 @@ + +.. image:: https://scan.coverity.com/projects/621/badge.svg + :target: https://scan.coverity.com/projects/621 + :alt: Coverity Scan Build Status + +.. image:: https://scan.coverity.com/projects/621/badge.svg + :alt: Coverity Scan Build Status diff --git a/lib/github/commands/rest2html b/lib/github/commands/rest2html index 47ced6ec..4df0ace6 100755 --- a/lib/github/commands/rest2html +++ b/lib/github/commands/rest2html @@ -93,21 +93,22 @@ class GitHubHTMLTranslator(HTMLTranslator): def depart_image(self, node): uri = node['uri'] ext = os.path.splitext(uri)[1].lower() - # we need to swap RST's obj with img tags + # we need to swap RST's use of `object` with `img` tags # see http://git.io/5me3dA if ext == ".svg": # preserve essential attributes atts = {} - atts['src'] = node['uri'] - atts['alt'] = node.get('alt', uri) - if 'width' in node: - atts['width'] = node['width'] - if 'height' in node: - atts['height'] = node['height'] - - # toss off obj tag + for attribute, value in node.attributes.items(): + # we have no time for empty values + if value: + if attribute == "uri": + atts['src'] = value + else: + atts[attribute] = value + + # toss off `object` tag self.body.pop() - # add on img with attributes + # add on `img` with attributes self.body.append(self.starttag(node, 'img', **atts)) self.body.append(self.context.pop())