-
Notifications
You must be signed in to change notification settings - Fork 90
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
Unify handling of SVG and other images in RST. #113
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
from __future__ import absolute_import, division, print_function | ||
|
||
import io | ||
import os.path | ||
|
||
from docutils.core import publish_parts | ||
from docutils.writers.html4css1 import HTMLTranslator, Writer | ||
|
@@ -25,26 +24,9 @@ | |
|
||
class ReadMeHTMLTranslator(HTMLTranslator): | ||
|
||
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)) | ||
# We need to swap RST's use of `object` with `img` tags | ||
# see http://git.io/5me3dA | ||
object_image_types = {'.swf': 'application/x-shockwave-flash'} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just make this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
|
||
SETTINGS = { | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<img alt="https://example.com/badge.png" src="https://example.com/badge.png"> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.. image:: https://example.com/badge.png |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<img alt="alternate text" src="https://example.com/badge.png"> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.. image:: https://example.com/badge.png | ||
:height: 100px | ||
:width: 25.0% | ||
:alt: alternate text | ||
:align: right |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<img src="https://example.com/badge.svg"> | ||
<img alt="https://example.com/badge.svg" src="https://example.com/badge.svg"> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<img alt="alternate text" src="https://example.com/badge.svg"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're kind of experiencing a regression here, right? Before, this: .. image:: https://example.com/badge.svg
:height: 100px
:width: 25.0%
:alt: alternate text
:align: right would become: <img align="right" alt="alternate text" height="100px" src="https://example.com/badge.svg" width="25.0%"> but now it becomes: <img alt="alternate text" src="https://example.com/badge.svg"> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but the current behavior is problematic:
#114 addresses image alignment and dimensions. Without unifying SVG with other image types, the subsequent PR would fix styling of non-SVG images only. (I created two PRs because the second relaxes what HTML is allowed, so there can be more discussion.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, thanks for the explanation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update this comment to mention that we're override the base class to not output svg with
object
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.