Skip to content

Commit 6cbc66b

Browse files
author
Kar Epker
committed
Fixed parser ignoring value of tab_length.
1 parent e594213 commit 6cbc66b

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

markdown/blockprocessors.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,6 @@ class OListProcessor(BlockProcessor):
300300
""" Process ordered list blocks. """
301301

302302
TAG = 'ol'
303-
# Detect an item (``1. item``). ``group(1)`` contains contents of item.
304-
RE = re.compile(r'^[ ]{0,3}\d+\.[ ]+(.*)')
305-
# Detect items on secondary lines. they can be of either list type.
306-
CHILD_RE = re.compile(r'^[ ]{0,3}((\d+\.)|[*+-])[ ]+(.*)')
307-
# Detect indented (nested) items of either type
308-
INDENT_RE = re.compile(r'^[ ]{4,7}((\d+\.)|[*+-])[ ]+.*')
309303
# The integer (python string) with which the lists starts (default=1)
310304
# Eg: If list is intialized as)
311305
# 3. Item
@@ -314,6 +308,20 @@ class OListProcessor(BlockProcessor):
314308
# List of allowed sibling tags.
315309
SIBLING_TAGS = ['ol', 'ul']
316310

311+
def __init__(self, parser):
312+
BlockProcessor.__init__(self, parser)
313+
# Detect an item (``1. item``). ``group(1)`` contains contents of item.
314+
self.RE = re.compile(''.join([
315+
r'^[ ]{0,', str(self.tab_length - 1), r'}\d+\.[ ]+(.*)']))
316+
# Detect items on secondary lines. they can be of either list type.
317+
self.CHILD_RE = re.compile(''.join([
318+
r'^[ ]{0,', str(self.tab_length - 1), '}((\d+\.)|[*+-])[ ]+(.*)']))
319+
# Detect indented (nested) items of either type
320+
self.INDENT_RE = re.compile(''.join([
321+
r'^[ ]{', str(self.tab_length), ',', str(self.tab_length * 2 - 1),
322+
r'}((\d+\.)|[*+-])[ ]+.*']))
323+
324+
317325
def test(self, parent, block):
318326
return bool(self.RE.match(block))
319327

@@ -407,7 +415,12 @@ class UListProcessor(OListProcessor):
407415
""" Process unordered list blocks. """
408416

409417
TAG = 'ul'
410-
RE = re.compile(r'^[ ]{0,3}[*+-][ ]+(.*)')
418+
419+
def __init__(self, parser):
420+
OListProcessor.__init__(self, parser)
421+
# Detect an item (``1. item``). ``group(1)`` contains contents of item.
422+
self.RE = re.compile(''.join([
423+
r'^[ ]{0,', str(self.tab_length - 1), r'}[*+-][ ]+(.*)']))
411424

412425

413426
class HashHeaderProcessor(BlockProcessor):

markdown/extensions/sane_lists.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,23 @@
2424

2525
class SaneOListProcessor(OListProcessor):
2626

27-
CHILD_RE = re.compile(r'^[ ]{0,3}((\d+\.))[ ]+(.*)')
2827
SIBLING_TAGS = ['ol']
2928

29+
def __init__(self, parser):
30+
OListProcessor.__init__(self, parser)
31+
self.CHILD_RE = re.compile(''.join([
32+
r'^[ ]{0,', str(self.tab_length - 1), r'}((\d+\.))[ ]+(.*)']))
33+
3034

3135
class SaneUListProcessor(UListProcessor):
3236

33-
CHILD_RE = re.compile(r'^[ ]{0,3}(([*+-]))[ ]+(.*)')
3437
SIBLING_TAGS = ['ul']
3538

39+
def __init__(self, parser):
40+
UListProcessor.__init__(self, parser)
41+
self.CHILD_RE = re.compile(''.join([
42+
r'^[ ]{0,', str(self.tab_length - 1), r'}(([*+-]))[ ]+(.*)']))
43+
3644

3745
class SaneListExtension(Extension):
3846
""" Add sane lists to Markdown. """

0 commit comments

Comments
 (0)