summaryrefslogtreecommitdiff
path: root/markdown/inlinepatterns.py
diff options
context:
space:
mode:
authorfacelessuser <faceless.shop@gmail.com>2017-10-25 20:19:19 -0600
committerfacelessuser <faceless.shop@gmail.com>2017-10-25 20:19:19 -0600
commit3887190c50b63f24c94ed8279975ffd136e62eb5 (patch)
tree2d7ccdd378189c978cf6565794276d68b4e54c02 /markdown/inlinepatterns.py
parente839a487edd1f6ceeb07577c015b5979b7a3ebd1 (diff)
downloadpython-markdown-image-url-spaces.tar.gz
Allow spaces in image urlimage-url-spaces
Preserving general pre-existing title output, ensure that image URL can have spaces (ref #590).
Diffstat (limited to 'markdown/inlinepatterns.py')
-rw-r--r--markdown/inlinepatterns.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py
index f9d0610..f86d59a 100644
--- a/markdown/inlinepatterns.py
+++ b/markdown/inlinepatterns.py
@@ -131,7 +131,7 @@ LINK_RE = NOIMG + BRK + \
r'''\(\s*(<.*?>|((?:(?:\(.*?\))|[^\(\)]))*?)\s*((['"])(.*?)\12\s*)?\)'''
# ![alttxt](http://x.com/) or ![alttxt](<http://x.com/>)
-IMAGE_LINK_RE = r'\!' + BRK + r'\s*\(\s*(<.*?>|([^"\)\s]+\s*"[^"]*"|[^\)\s]*))\s*\)'
+IMAGE_LINK_RE = r'\!' + BRK + r'\s*\(\s*(<.*?>|(?:([^"\)]+)\s*("[^"]*")|[^\)]*))\s*\)'
# [Google][3]
REFERENCE_RE = NOIMG + BRK + r'\s?\[([^\]]*)\]'
@@ -427,16 +427,21 @@ class ImagePattern(LinkPattern):
""" Return a img element from the given match. """
def handleMatch(self, m):
el = util.etree.Element("img")
- src_parts = m.group(9).split()
- if src_parts:
- src = src_parts[0]
- if src[0] == "<" and src[-1] == ">":
- src = src[1:-1]
- el.set('src', self.sanitize_url(self.unescape(src)))
+ if m.group(11):
+ # Preserving legacy split title logic
+ # which reduced white space (newlines, multiple spaces, etc.)
+ # to a single space.
+ title = ' '.join(m.group(11).split())
+ src = m.group(10).strip()
else:
- el.set('src', "")
- if len(src_parts) > 1:
- el.set('title', dequote(self.unescape(" ".join(src_parts[1:]))))
+ title = None
+ src = m.group(9).strip()
+ if src and src[0] == "<" and src[-1] == ">":
+ src = src[1:-1]
+ el.set('src', self.sanitize_url(self.unescape(src)))
+
+ if title:
+ el.set('title', dequote(self.unescape(title)))
if self.markdown.enable_attributes:
truealt = handleAttributes(m.group(2), el)