Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aca3fea

Browse files
committed
Merge pull request #1967 from mdboom/svg-comment-escape
svg double hyphen in plot title --
2 parents 98e37e8 + 3b1ab29 commit aca3fea

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/matplotlib/backends/backend_svg.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import division
22

3-
import os, base64, tempfile, urllib, gzip, io, sys, codecs
3+
import os, base64, tempfile, urllib, gzip, io, sys, codecs, re
44

55
import numpy as np
66

@@ -71,6 +71,11 @@ def escape_cdata(s):
7171
s = s.replace(u">", u">")
7272
return s
7373

74+
_escape_xml_comment = re.compile(r'-(?=-)')
75+
def escape_comment(s):
76+
s = escape_cdata(s)
77+
return _escape_xml_comment.sub('- ', s)
78+
7479
def escape_attrib(s):
7580
s = s.replace(u"&", u"&")
7681
s = s.replace(u"'", u"'")
@@ -146,7 +151,7 @@ def start(self, tag, attrib={}, **extra):
146151
def comment(self, comment):
147152
self.__flush()
148153
self.__write(self.__indentation[:len(self.__tags)])
149-
self.__write(u"<!-- %s -->\n" % escape_cdata(comment))
154+
self.__write(u"<!-- %s -->\n" % escape_comment(comment))
150155

151156
##
152157
# Adds character data to the output stream.

0 commit comments

Comments
 (0)