diff options
author | Waylan Limberg <waylan@gmail.com> | 2007-11-19 02:49:10 +0000 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2007-11-19 02:49:10 +0000 |
commit | cd83d0b4675418dad3bad6f0456828ef26378b1e (patch) | |
tree | 2e4deaaafc9e6a32f868041a64a9a0f47b9eac61 /markdown.py | |
parent | b1d6bce7de19905d6700602dc73bc8a1e59fea30 (diff) | |
download | markdown-cd83d0b4675418dad3bad6f0456828ef26378b1e.tar.gz markdown-cd83d0b4675418dad3bad6f0456828ef26378b1e.tar.bz2 markdown-cd83d0b4675418dad3bad6f0456828ef26378b1e.zip |
Removed recursion limit in _process_section(). Fixes [1763338]
Diffstat (limited to 'markdown.py')
-rw-r--r-- | markdown.py | 97 |
1 files changed, 47 insertions, 50 deletions
diff --git a/markdown.py b/markdown.py index 0b3010b..a20e747 100644 --- a/markdown.py +++ b/markdown.py @@ -38,7 +38,7 @@ MESSAGE_THRESHOLD = CRITICAL def message(level, text) : if level >= MESSAGE_THRESHOLD : - print text + print_error(text) # --------------- CONSTANTS YOU MIGHT WANT TO MODIFY ----------------- @@ -1284,67 +1284,63 @@ class Markdown: @param inList: a level @returns: None""" - if not lines : - return + # Loop through lines until none left. + while lines : - # Check if this section starts with a list, a blockquote or - # a code block + # Check if this section starts with a list, a blockquote or + # a code block - processFn = { 'ul' : self._processUList, - 'ol' : self._processOList, - 'quoted' : self._processQuote, - 'tabbed' : self._processCodeBlock } + processFn = { 'ul' : self._processUList, + 'ol' : self._processOList, + 'quoted' : self._processQuote, + 'tabbed' : self._processCodeBlock } - for regexp in ['ul', 'ol', 'quoted', 'tabbed'] : - m = RE.regExp[regexp].match(lines[0]) - if m : - processFn[regexp](parent_elem, lines, inList) - return - - # We are NOT looking at one of the high-level structures like - # lists or blockquotes. So, it's just a regular paragraph - # (though perhaps nested inside a list or something else). If - # we are NOT inside a list, we just need to look for a blank - # line to find the end of the block. If we ARE inside a - # list, however, we need to consider that a sublist does not - # need to be separated by a blank line. Rather, the following - # markup is legal: - # - # * The top level list item - # - # Another paragraph of the list. This is where we are now. - # * Underneath we might have a sublist. - # - - if inList : + for regexp in ['ul', 'ol', 'quoted', 'tabbed'] : + m = RE.regExp[regexp].match(lines[0]) + if m : + processFn[regexp](parent_elem, lines, inList) + return - start, theRest = self._linesUntil(lines, (lambda line: - RE.regExp['ul'].match(line) - or RE.regExp['ol'].match(line) - or not line.strip())) + # We are NOT looking at one of the high-level structures like + # lists or blockquotes. So, it's just a regular paragraph + # (though perhaps nested inside a list or something else). If + # we are NOT inside a list, we just need to look for a blank + # line to find the end of the block. If we ARE inside a + # list, however, we need to consider that a sublist does not + # need to be separated by a blank line. Rather, the following + # markup is legal: + # + # * The top level list item + # + # Another paragraph of the list. This is where we are now. + # * Underneath we might have a sublist. + # - self._processSection(parent_elem, start, - inList - 1, looseList = looseList) - self._processSection(parent_elem, theRest, - inList - 1, looseList = looseList) + if inList : + start, lines = self._linesUntil(lines, (lambda line: + RE.regExp['ul'].match(line) + or RE.regExp['ol'].match(line) + or not line.strip())) - else : # Ok, so it's just a simple block + self._processSection(parent_elem, start, + inList - 1, looseList = looseList) + inList = inList-1 - paragraph, theRest = self._linesUntil(lines, lambda line: - not line.strip()) + else : # Ok, so it's just a simple block - if len(paragraph) and paragraph[0].startswith('#') : - self._processHeader(parent_elem, paragraph) + paragraph, lines = self._linesUntil(lines, lambda line: + not line.strip()) - elif paragraph : - self._processParagraph(parent_elem, paragraph, - inList, looseList) + if len(paragraph) and paragraph[0].startswith('#') : + self._processHeader(parent_elem, paragraph) - if theRest : - theRest = theRest[1:] # skip the first (blank) line + elif paragraph : + self._processParagraph(parent_elem, paragraph, + inList, looseList) - self._processSection(parent_elem, theRest, inList) + if lines and not lines[0].strip() : + lines = lines[1:] # skip the first (blank) line def _processHeader(self, parent_elem, paragraph) : @@ -1358,6 +1354,7 @@ class Markdown: else : message(CRITICAL, "We've got a problem header!") + def _processParagraph(self, parent_elem, paragraph, inList, looseList) : list = self._handleInlineWrapper("\n".join(paragraph)) |