Skip to content

Swap RST's use of object for SVG to use image #287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/github/commands/foo.rst
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions lib/github/commands/rest2html
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -89,6 +90,28 @@ class GitHubHTMLTranslator(HTMLTranslator):
def depart_table(self, node):
self.body.append('</table>\n')

def depart_image(self, node):
uri = node['uri']
ext = os.path.splitext(uri)[1].lower()
# we need to swap RST's use of `object` with `img` tags
# see http://git.io/5me3dA
if ext == ".svg":
# preserve essential attributes
atts = {}
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
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
Expand Down
8 changes: 8 additions & 0 deletions test/markups/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions test/markups/README.rst.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ <h2>Header 2</h2>
</tr>
</tbody>
</table>
<a class="reference external image-reference" href="https://scan.coverity.com/projects/621"><img alt="Coverity Scan Build Status" src="https://scan.coverity.com/projects/621/badge.svg">
</a>
<img alt="Coverity Scan Build Status" src="https://scan.coverity.com/projects/621/badge.svg">