From 17292efebc8c64fe646935fc420cd703003c007f Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 20 Aug 2008 21:09:48 -0600 Subject: Pattern.compiled_re > I suppose one thing to do would be to somehow "annotate" nodes to > specify that they should not have their children processed. Artem, > what would you suggest? Then, nodes created with [...]() would > get their children processed, but those created with autolinks (<...>) > will be marked as done. Okay, I promise to get on the mail list, but this was such an obvious and elegant solution that I couldn't wait for the subscription to finish. Any objections to me starting a branch and pushing this to your gitorious project? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- markdown.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'markdown.py') diff --git a/markdown.py b/markdown.py index 40cfc61..a38c6ba 100755 --- a/markdown.py +++ b/markdown.py @@ -210,6 +210,11 @@ def handleAttributes(text, parent): return RE.regExp['attr'].sub(attributeCallback, text) +class AtomicString(str): + "A string which should not be further processed." + pass + + """ ====================================================================== ========================== PRE-PROCESSORS ============================ @@ -776,7 +781,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): @@ -789,9 +794,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;' % @@ -1661,6 +1666,10 @@ class Markdown: Returns: String with placeholders. """ + + if isinstance(data, AtomicString): + return data + startIndex = 0 while patternIndex < len(self.inlinePatterns): -- cgit v1.2.3 From 8ba141154f663f2e46e6124396eca6d0443fdb37 Mon Sep 17 00:00:00 2001 From: Yuri Takhteyev Date: Wed, 20 Aug 2008 22:57:46 -0700 Subject: Changing string to unicode in Neale's fix. Adding test cases. --- markdown.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'markdown.py') diff --git a/markdown.py b/markdown.py index a38c6ba..69616be 100755 --- a/markdown.py +++ b/markdown.py @@ -210,7 +210,7 @@ def handleAttributes(text, parent): return RE.regExp['attr'].sub(attributeCallback, text) -class AtomicString(str): +class AtomicString(unicode): "A string which should not be further processed." pass -- cgit v1.2.3 From c846dbced12091cfa1b783f268db96d8c87be030 Mon Sep 17 00:00:00 2001 From: Yuri Takhteyev Date: Thu, 21 Aug 2008 10:57:52 -0700 Subject: "sanatize_url" -> "sanitize_url" --- markdown.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'markdown.py') diff --git a/markdown.py b/markdown.py index 69616be..ef875de 100755 --- a/markdown.py +++ b/markdown.py @@ -671,7 +671,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 +680,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 +722,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 +757,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 +769,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) -- cgit v1.2.3