aboutsummaryrefslogtreecommitdiffstats
path: root/markdown.py
diff options
context:
space:
mode:
authorArtem Yunusov <nedrlab@gmail.com>2008-08-21 23:56:34 +0500
committerArtem Yunusov <nedrlab@gmail.com>2008-08-21 23:56:34 +0500
commit15fe229e19f218eb99dfb09cc745705a9c2d1e97 (patch)
tree827a01fa82a097774088a4196342bf5bd4ecd72d /markdown.py
parentb4362b3bf562bfb1b79bff9aee07feba32983e58 (diff)
parentc846dbced12091cfa1b783f268db96d8c87be030 (diff)
downloadmarkdown-15fe229e19f218eb99dfb09cc745705a9c2d1e97.tar.gz
markdown-15fe229e19f218eb99dfb09cc745705a9c2d1e97.tar.bz2
markdown-15fe229e19f218eb99dfb09cc745705a9c2d1e97.zip
Merge git@gitorious.org:python-markdown/mainline
Conflicts: markdown.py
Diffstat (limited to 'markdown.py')
-rwxr-xr-xmarkdown.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/markdown.py b/markdown.py
index 628d7d7..dec3e86 100755
--- a/markdown.py
+++ b/markdown.py
@@ -215,6 +215,11 @@ def handleAttributes(text, parent):
return RE.regExp['attr'].sub(attributeCallback, text)
+class AtomicString(unicode):
+ "A string which should not be further processed."
+ pass
+
+
"""
======================================================================
========================== PRE-PROCESSORS ============================
@@ -671,7 +676,7 @@ class LinkPattern (Pattern):
if href:
if href[0] == "<":
href = href[1:-1]
- el.set("href", self.sanatize_url(href.strip()))
+ el.set("href", self.sanitize_url(href.strip()))
else:
el.set("href", "")
@@ -680,7 +685,7 @@ class LinkPattern (Pattern):
el.set("title", title)
return el
- def sanatize_url(self, url):
+ def sanitize_url(self, url):
"""
Sanitize a url against xss attacks in "safe_mode".
@@ -722,7 +727,7 @@ class ImagePattern(LinkPattern):
src = src_parts[0]
if src[0] == "<" and src[-1] == ">":
src = src[1:-1]
- el.set('src', self.sanatize_url(src))
+ el.set('src', self.sanitize_url(src))
else:
el.set('src', "")
if len(src_parts) > 1:
@@ -757,7 +762,7 @@ class ReferencePattern(LinkPattern):
def makeTag(self, href, title, text):
el = etree.Element('a')
- el.set('href', self.sanatize_url(href))
+ el.set('href', self.sanitize_url(href))
if title:
el.set('title', title)
@@ -769,7 +774,7 @@ class ImageReferencePattern (ReferencePattern):
""" Match to a stored reference and return img element. """
def makeTag(self, href, title, text):
el = etree.Element("img")
- el.set("src", self.sanatize_url(href))
+ el.set("src", self.sanitize_url(href))
if title:
el.set("title", title)
el.set("alt", text)
@@ -781,7 +786,7 @@ class AutolinkPattern (Pattern):
def handleMatch(self, m):
el = etree.Element("a")
el.set('href', m.group(2))
- el.text = m.group(2)
+ el.text = AtomicString(m.group(2))
return el
class AutomailPattern (Pattern):
@@ -794,9 +799,9 @@ class AutomailPattern (Pattern):
email = m.group(2)
if email.startswith("mailto:"):
email = email[len("mailto:"):]
- el.text = ""
- for letter in email:
- el.text += codepoint2name(ord(letter))
+
+ letters = [codepoint2name(ord(letter)) for letter in email]
+ el.text = AtomicString(''.join(letters))
mailto = "mailto:" + email
mailto = "".join([AMP_SUBSTITUTE + '#%d;' %
@@ -1678,9 +1683,10 @@ class Markdown:
Returns: String with placeholders.
"""
+
if isinstance(data, AtomicString):
return data
-
+
startIndex = 0
while patternIndex < len(self.inlinePatterns):