Skip to content

Commit

Permalink
Fixed parser ignoring value of tab_length.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kar Epker committed Jun 1, 2015
1 parent e594213 commit 6cbc66b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
27 changes: 20 additions & 7 deletions markdown/blockprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))

Expand Down Expand Up @@ -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):
Expand Down
12 changes: 10 additions & 2 deletions markdown/extensions/sane_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,23 @@

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. """
Expand Down

0 comments on commit 6cbc66b

Please sign in to comment.