aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2007-10-11 03:22:28 +0000
committerWaylan Limberg <waylan@gmail.com>2007-10-11 03:22:28 +0000
commit0c59b31f02906e6c1c35928afa41bab115cf4ec0 (patch)
tree1b3074b544ae4cd965a98e318533ade5570c9c58
parenta9b2d38626a95ccad8e4bbdc9d2cc7325ab7b928 (diff)
downloadmarkdown-0c59b31f02906e6c1c35928afa41bab115cf4ec0.tar.gz
markdown-0c59b31f02906e6c1c35928afa41bab115cf4ec0.tar.bz2
markdown-0c59b31f02906e6c1c35928afa41bab115cf4ec0.zip
Factored out header and paragraph code from _processSection() to _processHeader() & _processParagraph(). See [1793419].
-rw-r--r--markdown.py59
1 files changed, 32 insertions, 27 deletions
diff --git a/markdown.py b/markdown.py
index 0b7fac0..d09f1b2 100644
--- a/markdown.py
+++ b/markdown.py
@@ -1023,7 +1023,7 @@ class CorePatterns :
effort."""
patterns = {
- 'header': r'(#*)\s*([^#]*)(#*)', # # A title
+ 'header': r'(#*)([^#]*)(#*)', # # A title
'reference-def' : r'(\ ?\ ?\ ?)\[([^\]]*)\]:\s*([^ ]*)(.*)',
# [Google]: http://www.google.com/
'containsline': r'([-]*)$|^([=]*)', # -----, =====, etc.
@@ -1287,42 +1287,47 @@ class Markdown:
not line.strip())
if len(paragraph) and paragraph[0].startswith('#') :
- m = RE.regExp['header'].match(paragraph[0])
- if m :
- level = len(m.group(1))
- h = self.doc.createElement("h%d" % level)
- parent_elem.appendChild(h)
- for item in self._handleInlineWrapper(m.group(2).strip()) :
- h.appendChild(item)
- else :
- message(CRITICAL, "We've got a problem header!")
+ self._processHeader(parent_elem, paragraph)
elif paragraph :
+ self._processParagraph(parent_elem, paragraph,
+ inList, looseList)
- list = self._handleInlineWrapper("\n".join(paragraph))
+ if theRest :
+ theRest = theRest[1:] # skip the first (blank) line
- if ( parent_elem.nodeName == 'li'
- and not (looseList or parent_elem.childNodes)):
+ self._processSection(parent_elem, theRest, inList)
- #and not parent_elem.childNodes) :
- # If this is the first paragraph inside "li", don't
- # put <p> around it - append the paragraph bits directly
- # onto parent_elem
- el = parent_elem
- else :
- # Otherwise make a "p" element
- el = self.doc.createElement("p")
- parent_elem.appendChild(el)
- for item in list :
- el.appendChild(item)
+ def _processHeader(self, parent_elem, paragraph) :
+ m = RE.regExp['header'].match(paragraph[0])
+ if m :
+ level = len(m.group(1))
+ h = self.doc.createElement("h%d" % level)
+ parent_elem.appendChild(h)
+ for item in self._handleInlineWrapper(m.group(2).strip()) :
+ h.appendChild(item)
+ else :
+ message(CRITICAL, "We've got a problem header!")
- if theRest :
- theRest = theRest[1:] # skip the first (blank) line
+ def _processParagraph(self, parent_elem, paragraph, inList, looseList) :
+ list = self._handleInlineWrapper("\n".join(paragraph))
- self._processSection(parent_elem, theRest, inList)
+ if ( parent_elem.nodeName == 'li'
+ and not (looseList or parent_elem.childNodes)):
+ # If this is the first paragraph inside "li", don't
+ # put <p> around it - append the paragraph bits directly
+ # onto parent_elem
+ el = parent_elem
+ else :
+ # Otherwise make a "p" element
+ el = self.doc.createElement("p")
+ parent_elem.appendChild(el)
+ for item in list :
+ el.appendChild(item)
+
def _processUList(self, parent_elem, lines, inList) :
self._processList(parent_elem, lines, inList,