Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions markdown/blockprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def build_block_parser(md_instance, **kwargs):
return parser


class BlockProcessor:
class BlockProcessor(object):
""" Base class for block processors.

Each subclass will provide the methods below to work with the source and
Expand Down Expand Up @@ -141,7 +141,7 @@ class ListIndentProcessor(BlockProcessor):
LIST_TYPES = ['ul', 'ol']

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

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

def __init__(self, parser):
super(OListProcessor, self).__init__(parser)
# Detect an item (``1. item``). ``group(1)`` contains contents of item.
self.RE = re.compile(r'^[ ]{0,%d}\d+\.[ ]+(.*)' % (self.tab_length - 1))
# Detect items on secondary lines. they can be of either list type.
self.CHILD_RE = re.compile(r'^[ ]{0,%d}((\d+\.)|[*+-])[ ]+(.*)' %
(self.tab_length - 1))
# Detect indented (nested) items of either type
self.INDENT_RE = re.compile(r'^[ ]{%d,%d}((\d+\.)|[*+-])[ ]+.*' %
(self.tab_length, self.tab_length * 2 - 1))

def test(self, parent, block):
return bool(self.RE.match(block))

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

TAG = 'ul'
RE = re.compile(r'^[ ]{0,3}[*+-][ ]+(.*)')

def __init__(self, parser):
super(UListProcessor, self).__init__(parser)
# Detect an item (``1. item``). ``group(1)`` contains contents of item.
self.RE = re.compile(r'^[ ]{0,%d}[*+-][ ]+(.*)' % (self.tab_length - 1))


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


class SaneUListProcessor(UListProcessor):

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

def __init__(self, parser):
super(SaneUListProcessor, self).__init__(parser)
self.CHILD_RE = re.compile(r'^[ ]{0,%d}(([*+-]))[ ]+(.*)' %
(self.tab_length - 1))


class SaneListExtension(Extension):
""" Add sane lists to Markdown. """
Expand Down