aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--markdown/blockprocessors.py27
-rw-r--r--markdown/extensions/sane_lists.py12
2 files changed, 30 insertions, 9 deletions
diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py
index 29db022..4b296d5 100644
--- a/markdown/blockprocessors.py
+++ b/markdown/blockprocessors.py
@@ -300,12 +300,6 @@ class OListProcessor(BlockProcessor):
""" Process ordered list blocks. """
TAG = 'ol'
- # Detect an item (``1. item``). ``group(1)`` contains contents of item.
- RE = re.compile(r'^[ ]{0,3}\d+\.[ ]+(.*)')
- # Detect items on secondary lines. they can be of either list type.
- 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
@@ -314,6 +308,20 @@ class OListProcessor(BlockProcessor):
# List of allowed sibling tags.
SIBLING_TAGS = ['ol', 'ul']
+ def __init__(self, parser):
+ BlockProcessor.__init__(self, parser)
+ # Detect an item (``1. item``). ``group(1)`` contains contents of item.
+ self.RE = re.compile(''.join([
+ r'^[ ]{0,', str(self.tab_length - 1), r'}\d+\.[ ]+(.*)']))
+ # Detect items on secondary lines. they can be of either list type.
+ self.CHILD_RE = re.compile(''.join([
+ r'^[ ]{0,', str(self.tab_length - 1), '}((\d+\.)|[*+-])[ ]+(.*)']))
+ # Detect indented (nested) items of either type
+ self.INDENT_RE = re.compile(''.join([
+ r'^[ ]{', str(self.tab_length), ',', str(self.tab_length * 2 - 1),
+ r'}((\d+\.)|[*+-])[ ]+.*']))
+
+
def test(self, parent, block):
return bool(self.RE.match(block))
@@ -407,7 +415,12 @@ class UListProcessor(OListProcessor):
""" Process unordered list blocks. """
TAG = 'ul'
- RE = re.compile(r'^[ ]{0,3}[*+-][ ]+(.*)')
+
+ def __init__(self, parser):
+ OListProcessor.__init__(self, parser)
+ # Detect an item (``1. item``). ``group(1)`` contains contents of item.
+ self.RE = re.compile(''.join([
+ r'^[ ]{0,', str(self.tab_length - 1), r'}[*+-][ ]+(.*)']))
class HashHeaderProcessor(BlockProcessor):
diff --git a/markdown/extensions/sane_lists.py b/markdown/extensions/sane_lists.py
index 213c8a6..e1f2fc3 100644
--- a/markdown/extensions/sane_lists.py
+++ b/markdown/extensions/sane_lists.py
@@ -24,15 +24,23 @@ import re
class SaneOListProcessor(OListProcessor):
- CHILD_RE = re.compile(r'^[ ]{0,3}((\d+\.))[ ]+(.*)')
SIBLING_TAGS = ['ol']
+ def __init__(self, parser):
+ OListProcessor.__init__(self, parser)
+ self.CHILD_RE = re.compile(''.join([
+ r'^[ ]{0,', str(self.tab_length - 1), r'}((\d+\.))[ ]+(.*)']))
+
class SaneUListProcessor(UListProcessor):
- CHILD_RE = re.compile(r'^[ ]{0,3}(([*+-]))[ ]+(.*)')
SIBLING_TAGS = ['ul']
+ def __init__(self, parser):
+ UListProcessor.__init__(self, parser)
+ self.CHILD_RE = re.compile(''.join([
+ r'^[ ]{0,', str(self.tab_length - 1), r'}(([*+-]))[ ]+(.*)']))
+
class SaneListExtension(Extension):
""" Add sane lists to Markdown. """