diff options
author | Waylan Limberg <waylan@gmail.com> | 2012-02-02 06:19:41 -0500 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2012-02-02 06:19:41 -0500 |
commit | 9834966294597181545d2f987f223b6ca1aeb070 (patch) | |
tree | 29c4f3a32e0672438cde07b534df49b003a9cc61 /markdown/preprocessors.py | |
parent | 3b6c63fbd35509e1499e9502a78c82bfa2b17957 (diff) | |
download | markdown-9834966294597181545d2f987f223b6ca1aeb070.tar.gz markdown-9834966294597181545d2f987f223b6ca1aeb070.tar.bz2 markdown-9834966294597181545d2f987f223b6ca1aeb070.zip |
Fixed #78. Added support for two line link refs.
Also refactored the reference preprocessor to make this a little easier to
implement. Regex does more now.
Diffstat (limited to 'markdown/preprocessors.py')
-rw-r--r-- | markdown/preprocessors.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py index 55dd9ab..e7743fb 100644 --- a/markdown/preprocessors.py +++ b/markdown/preprocessors.py @@ -257,25 +257,26 @@ class HtmlBlockPreprocessor(Preprocessor): class ReferencePreprocessor(Preprocessor): """ Remove reference definitions from text and store for later use. """ - RE = re.compile(r'^(\ ?\ ?\ ?)\[([^\]]*)\]:\s*([^ ]*)(.*)$', re.DOTALL) + TITLE = r'[ ]*(\"(.*)\"|\'(.*)\'|\((.*)\))[ ]*' + RE = re.compile(r'^[ ]{0,3}\[([^\]]*)\]:\s*([^ ]*)[ ]*(%s)?$' % TITLE, re.DOTALL) + TITLE_RE = re.compile(r'^%s$' % TITLE) def run (self, lines): new_text = []; - for line in lines: + while lines: + line = lines.pop(0) m = self.RE.match(line) if m: - id = m.group(2).strip().lower() - link = m.group(3).lstrip('<').rstrip('>') - t = m.group(4).strip() # potential title + id = m.group(1).strip().lower() + link = m.group(2).lstrip('<').rstrip('>') + t = m.group(5) or m.group(6) or m.group(7) if not t: - self.markdown.references[id] = (link, t) - elif (len(t) >= 2 - and (t[0] == t[-1] == "\"" - or t[0] == t[-1] == "\'" - or (t[0] == "(" and t[-1] == ")") ) ): - self.markdown.references[id] = (link, t[1:-1]) - else: - new_text.append(line) + # Check next line for title + tm = self.TITLE_RE.match(lines[0]) + if tm: + lines.pop(0) + t = tm.group(2) or tm.group(3) or tm.group(4) + self.markdown.references[id] = (link, t) else: new_text.append(line) |