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
svg double hyphen in plot title -- #1967
Conversation
I think as long as we find a way to escape it, we don't need to worry about unescaping (since matplotlib doesn't read XML/SVG files at all). I'll work up a PR here shortly. |
A solution is attached. @cirosantilli, could you please confirm it works for you? FWIW, I took the approach from docbook, which is to convert |
I'm sorry but I haven't yet been able to install matplotlib from source to test it out, I'll try to do that for the time being, I see that you approach is based on
so the comment would still broken (please check). I think the way to go is still with
which works because of the lookahead: "---" --> "- - -" as for unscapping, I agree that it is not directly necessary for matplotlib, I just feel it is a good practice to give unscape to escapes, since one day some user will want to use the comment content grammatically and will have to write this himself. Of course, not sure it is worth the extra code maintenance... |
Ah, thanks. Good catch. I will update this to use the regex. I'm not too concerned about the unescaping at this point -- comments shouldn't ever really by used grammatically anyway... |
haha sorry I meant programatically, not gramatically =) |
@@ -71,6 +71,11 @@ def escape_cdata(s): | |||
s = s.replace(u">", u">") | |||
return s | |||
|
|||
def escape_comment(s): | |||
escape_xml_comment = re.compile( r'-(?=-)') |
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.
Perhaps compile this re outside of the function?
👍 - LGTM |
svg double hyphen in plot title --
a double hyphen in plot title breaks the svg output because the double hyphen
--
gets included in a xml comment, breaking itminimal example:
now try and open svg output it with firefox and it will point at the error line, 479 in version 1.2.1. which contains:
but xml comments cannot contain
--
http://stackoverflow.com/questions/10842131/xml-comments-andI could not find in the stdlib a standard way to escape/unescape double hyphens, but if anyone does, we should use it.
if an standard way does not exist, my proposed solution is: replace
--
with something else in the svg comments. I suggest--
with-.-
, where.
is any literal character-.-
with-..-
-..-
with-...-
and that this be done in an overlapping manner:
---
becomes-.-.-
This can be achieved with the following class:
I just don't know exactly where to plug this, but it should take 5 mins for someone who knows the svg
savefig
architecture.