Skip to content

Commit c7410d1

Browse files
committed
Merge pull request #415 from karepker/master
Fixed #414 parser ignoring value of `tab_length`
2 parents e594213 + 99257e4 commit c7410d1

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

markdown/blockprocessors.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def build_block_parser(md_instance, **kwargs):
3838
return parser
3939

4040

41-
class BlockProcessor:
41+
class BlockProcessor(object):
4242
""" Base class for block processors.
4343
4444
Each subclass will provide the methods below to work with the source and
@@ -141,7 +141,7 @@ class ListIndentProcessor(BlockProcessor):
141141
LIST_TYPES = ['ul', 'ol']
142142

143143
def __init__(self, *args):
144-
BlockProcessor.__init__(self, *args)
144+
super(ListIndentProcessor, self).__init__(*args)
145145
self.INDENT_RE = re.compile(r'^(([ ]{%s})+)' % self.tab_length)
146146

147147
def test(self, parent, block):
@@ -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,17 @@ class OListProcessor(BlockProcessor):
314308
# List of allowed sibling tags.
315309
SIBLING_TAGS = ['ol', 'ul']
316310

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

@@ -407,7 +412,11 @@ class UListProcessor(OListProcessor):
407412
""" Process unordered list blocks. """
408413

409414
TAG = 'ul'
410-
RE = re.compile(r'^[ ]{0,3}[*+-][ ]+(.*)')
415+
416+
def __init__(self, parser):
417+
super(UListProcessor, self).__init__(parser)
418+
# Detect an item (``1. item``). ``group(1)`` contains contents of item.
419+
self.RE = re.compile(r'^[ ]{0,%d}[*+-][ ]+(.*)' % (self.tab_length - 1))
411420

412421

413422
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+
super(SaneOListProcessor, self).__init__(parser)
31+
self.CHILD_RE = re.compile(r'^[ ]{0,%d}((\d+\.))[ ]+(.*)' %
32+
(self.tab_length - 1))
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+
super(SaneUListProcessor, self).__init__(parser)
41+
self.CHILD_RE = re.compile(r'^[ ]{0,%d}(([*+-]))[ ]+(.*)' %
42+
(self.tab_length - 1))
43+
3644

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

0 commit comments

Comments
 (0)