diff options
author | Waylan Limberg <waylan@gmail.com> | 2011-04-28 23:10:58 -0400 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2011-04-28 23:10:58 -0400 |
commit | ad83ad5c426b508ba0ace30ea83b3e60ec23b8ef (patch) | |
tree | 138283fb5739a2c33bd0c3f85f384968c1a32f4d | |
parent | 08b9b6f879ad81f296abb22b3752a3092b57ee03 (diff) | |
parent | c385e5fc0a9fe7517b4afdb5b3f9c174ae0766de (diff) | |
download | markdown-ad83ad5c426b508ba0ace30ea83b3e60ec23b8ef.tar.gz markdown-ad83ad5c426b508ba0ace30ea83b3e60ec23b8ef.tar.bz2 markdown-ad83ad5c426b508ba0ace30ea83b3e60ec23b8ef.zip |
Merge commit 'refs/merge-requests/13' of git://gitorious.org/python-markdown/mainline into merge-requests/13
-rw-r--r-- | markdown/blockprocessors.py | 17 | ||||
-rw-r--r-- | tests/misc/some-test.html | 4 |
2 files changed, 18 insertions, 3 deletions
diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index 2f15578..5949c00 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -301,6 +301,11 @@ class OListProcessor(BlockProcessor): CHILD_RE = re.compile(r'^[ ]{0,3}((\d+\.)|[*+-])[ ]+(.*)') # Detect indented (nested) items of either type INDENT_RE = re.compile(r'^[ ]{4,7}((\d+\.)|[*+-])[ ]+.*') + # The integer (python string) with which the lists starts (default=1) + # Eg: If list is intialized as) + # 3. Item + # The ol tag will get starts="3" attribute + STARTSWITH = '1' def test(self, parent, block): return bool(self.RE.match(block)) @@ -340,6 +345,10 @@ class OListProcessor(BlockProcessor): else: # This is a new list so create parent with appropriate tag. lst = util.etree.SubElement(parent, self.TAG) + # Check if a custom start integer is set + if self.STARTSWITH !='1': + lst.attrib['start'] = self.STARTSWITH + self.parser.state.set('list') # Loop through items in block, recursively parsing each with the # appropriate parent. @@ -359,7 +368,13 @@ class OListProcessor(BlockProcessor): for line in block.split('\n'): m = self.CHILD_RE.match(line) if m: - # This is a new item. Append + # This is a new list item + # Check first item for the start index + if not items and self.TAG=='ol': + # Detect the integer value of first list item + INTEGER_RE = re.compile('(\d+)') + self.STARTSWITH = INTEGER_RE.match(m.group(1)).group() + # Append to the list items.append(m.group(3)) elif self.INDENT_RE.match(line): # This is an indented (possibly nested) item. diff --git a/tests/misc/some-test.html b/tests/misc/some-test.html index b78683f..92e7262 100644 --- a/tests/misc/some-test.html +++ b/tests/misc/some-test.html @@ -51,7 +51,7 @@ ok with a bunch of items</li> <li> <p>Mostly fruits</p> -<ol> +<ol start="3"> <li>Apple</li> <li>Pare</li> </ol> @@ -65,4 +65,4 @@ Another code example * Lists and similar stuff > Should be ignored -</code></pre>
\ No newline at end of file +</code></pre> |