diff options
Diffstat (limited to 'markdown')
-rw-r--r-- | markdown/core.py | 4 | ||||
-rw-r--r-- | markdown/extensions/footnotes.py | 2 | ||||
-rw-r--r-- | markdown/extensions/legacy_em.py | 4 | ||||
-rw-r--r-- | markdown/extensions/wikilinks.py | 4 | ||||
-rw-r--r-- | markdown/inlinepatterns.py | 59 | ||||
-rw-r--r-- | markdown/treeprocessors.py | 7 |
6 files changed, 28 insertions, 52 deletions
diff --git a/markdown/core.py b/markdown/core.py index 0b21d06..47a6c78 100644 --- a/markdown/core.py +++ b/markdown/core.py @@ -29,8 +29,8 @@ class Markdown(object): 'xhtml': to_xhtml_string, } - ESCAPED_CHARS = ['\\', '`', '*', '_', '{', '}', '[', ']', - '(', ')', '>', '#', '+', '-', '.', '!'] + ESCAPED_CHARS = ['\\', '`', '*', '_', '{', '}', '[', ']', '&', + '(', ')', '<', '>', '#', '+', '-', '.', '!'] def __init__(self, **kwargs): """ diff --git a/markdown/extensions/footnotes.py b/markdown/extensions/footnotes.py index c04ad68..a237ae7 100644 --- a/markdown/extensions/footnotes.py +++ b/markdown/extensions/footnotes.py @@ -264,7 +264,7 @@ class FootnotePattern(Pattern): self.footnotes = footnotes def handleMatch(self, m): - id = m.group(2) + id = m.group(1) if id in self.footnotes.footnotes.keys(): sup = etree.Element("sup") a = etree.SubElement(sup, "a") diff --git a/markdown/extensions/legacy_em.py b/markdown/extensions/legacy_em.py index 47963a8..54d2028 100644 --- a/markdown/extensions/legacy_em.py +++ b/markdown/extensions/legacy_em.py @@ -15,8 +15,8 @@ from __future__ import unicode_literals from . import Extension from ..inlinepatterns import SimpleTagPattern -EMPHASIS_RE = r'(\*|_)(.+?)\2' -STRONG_RE = r'(\*{2}|_{2})(.+?)\2' +EMPHASIS_RE = r'(\*|_)(.+?)\1' +STRONG_RE = r'(\*{2}|_{2})(.+?)\1' class LegacyEmExtension(Extension): diff --git a/markdown/extensions/wikilinks.py b/markdown/extensions/wikilinks.py index 14f47a1..7b8899b 100644 --- a/markdown/extensions/wikilinks.py +++ b/markdown/extensions/wikilinks.py @@ -57,9 +57,9 @@ class WikiLinks(Pattern): self.config = config def handleMatch(self, m): - if m.group(2).strip(): + if m.group(1).strip(): base_url, end_url, html_class = self._getMeta() - label = m.group(2).strip() + label = m.group(1).strip() url = self.config['build_url'](label, base_url, end_url) a = etree.Element('a') a.text = label diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py index 54d7644..5426c8c 100644 --- a/markdown/inlinepatterns.py +++ b/markdown/inlinepatterns.py @@ -120,7 +120,7 @@ STRONG_EM_RE = r'(\*|_)\1{2}(.+?)\1{2}(.*?)\1' # [text](url) or [text](<url>) or [text](url "title") LINK_RE = NOIMG + BRK + \ - r'''\(\s*(<.*?>|((?:(?:\(.*?\))|[^\(\)]))*?)\s*((['"])(.*?)\1\s*)?\)''' + r'''\(\s*(<.*?>|((?:(?:\(.*?\))|[^\(\)]))*?)\s*((['"])(.*?)\11\s*)?\)''' #  or  IMAGE_LINK_RE = r'\!' + BRK + r'\s*\((<.*?>|([^")]+"[^"]*"|[^\)]*))\)' @@ -207,22 +207,15 @@ class Pattern(object): return self.__class__.__name__ def unescape(self, text): - """ Return unescaped text given text with an inline placeholder. """ - try: - stash = self.md.treeprocessors['inline'].stashed_nodes - except KeyError: # pragma: no cover + """ Processed any backslash escaped chars in string. """ + if not isinstance(text, util.text_type): return text - - def get_stash(m): - id = m.group(0) - if id in stash: - value = stash.get(id) - if isinstance(value, util.string_type): - return value - else: - # An etree Element - return text content only - return ''.join(value.itertext()) - return util.INLINE_PLACEHOLDER_RE.sub(get_stash, text) + def sub(m): + if m.group(1) in self.md.ESCAPED_CHARS: + return m.group(1) + else: + return m.group(0) + return re.sub(ESCAPE_RE, sub, text) class SimpleTextPattern(Pattern): @@ -295,28 +288,10 @@ class DoubleTagPattern(SimpleTagPattern): class HtmlPattern(Pattern): """ Store raw inline html and return a placeholder. """ def handleMatch(self, m): - rawhtml = self.unescape(m.group(1)) + rawhtml = m.group(1) place_holder = self.md.htmlStash.store(rawhtml) return place_holder - def unescape(self, text): - """ Return unescaped text given text with an inline placeholder. """ - try: - stash = self.md.treeprocessors['inline'].stashed_nodes - except KeyError: # pragma: no cover - return text - - def get_stash(m): - id = m.group(0) - value = stash.get(id) - if value is not None: - try: - return self.md.serializer(value) - except: - return '\%s' % value - - return util.INLINE_PLACEHOLDER_RE.sub(get_stash, text) - class LinkPattern(Pattern): """ Return a link element from the given match. """ @@ -334,7 +309,7 @@ class LinkPattern(Pattern): el.set("href", "") if title: - title = dequote(self.unescape(title)) + title = self.unescape(dequote(title)) el.set("title", title) return el @@ -352,8 +327,8 @@ class ImagePattern(LinkPattern): else: el.set('src', "") if len(src_parts) > 1: - el.set('title', dequote(self.unescape(" ".join(src_parts[1:])))) - el.set('alt', self.unescape(m.group(2))) + el.set('title', self.unescape(dequote(" ".join(src_parts[1:])))) + el.set('alt', self.unescape(m.group(1))) return el @@ -379,7 +354,7 @@ class ReferencePattern(LinkPattern): href, title = self.md.references[id] text = m.group(1) - return self.makeTag(href, title, text) + return self.makeTag(self.unescape(href), self.unescape(title), text) def makeTag(self, href, title, text): el = util.etree.Element('a') @@ -399,7 +374,7 @@ class ImageReferencePattern(ReferencePattern): el.set("src", href) if title: el.set("title", title) - el.set("alt", self.unescape(text)) + el.set("alt", text) return el @@ -407,7 +382,7 @@ class AutolinkPattern(Pattern): """ Return a link Element given an autolink (`<http://example/com>`). """ def handleMatch(self, m): el = util.etree.Element("a") - el.set('href', self.unescape(m.group(1))) + el.set('href', m.group(1)) el.text = util.AtomicString(m.group(1)) return el @@ -418,7 +393,7 @@ class AutomailPattern(Pattern): """ def handleMatch(self, m): el = util.etree.Element('a') - email = self.unescape(m.group(1)) + email = m.group(1) if email.startswith("mailto:"): email = email[len("mailto:"):] diff --git a/markdown/treeprocessors.py b/markdown/treeprocessors.py index d2036f6..c07acdc 100644 --- a/markdown/treeprocessors.py +++ b/markdown/treeprocessors.py @@ -48,7 +48,7 @@ class InlineProcessor(Treeprocessor): def __init__(self, md): super(InlineProcessor, self).__init__(md) - self.TOKEN_RE = re.compile(r'|'.join('\\{0}'.format(x) for x in md.ESCAPED_CHARS)) + self.TOKEN_RE = re.compile(r'|'.join('\\{0}'.format(x) for x in md.ESCAPED_CHARS + [' \n'])) def apply_patterns(self, text): """ @@ -61,10 +61,11 @@ class InlineProcessor(Treeprocessor): match = pattern.getCompiledRegExp().match(text) if match: node = pattern.handleMatch(match) - text = text[match.end():] + if node is not None: + text = text[match.end():] break - if not match: + if not match or node is None: # Step forward one character return text[0], None, text[1:] |