From 6cbc66b4e63de0ddba7413b653591274fc6587cf Mon Sep 17 00:00:00 2001 From: Kar Epker Date: Mon, 1 Jun 2015 01:03:51 -0400 Subject: Fixed parser ignoring value of tab_length. --- markdown/blockprocessors.py | 27 ++++++++++++++++++++------- markdown/extensions/sane_lists.py | 12 ++++++++++-- 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. """ -- cgit v1.2.3 From cced40a37862de25c74f805dcb23fe3dd84766d5 Mon Sep 17 00:00:00 2001 From: Kar Epker Date: Mon, 1 Jun 2015 13:19:46 -0400 Subject: Changed line continuations to satisfy pylint. --- markdown/blockprocessors.py | 23 +++++++++++++---------- markdown/extensions/sane_lists.py | 10 ++++++---- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index 4b296d5..43a384d 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -311,16 +311,18 @@ class OListProcessor(BlockProcessor): 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+\.[ ]+(.*)'])) + 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+\.)|[*+-])[ ]+(.*)'])) + self.CHILD_RE = re.compile( + ''.join([r'^[ ]{0,', str(self.tab_length - 1), + r'}((\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+\.)|[*+-])[ ]+.*'])) - + 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)) @@ -419,8 +421,9 @@ class UListProcessor(OListProcessor): 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'}[*+-][ ]+(.*)'])) + 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 e1f2fc3..f464ac0 100644 --- a/markdown/extensions/sane_lists.py +++ b/markdown/extensions/sane_lists.py @@ -28,8 +28,9 @@ class SaneOListProcessor(OListProcessor): def __init__(self, parser): OListProcessor.__init__(self, parser) - self.CHILD_RE = re.compile(''.join([ - r'^[ ]{0,', str(self.tab_length - 1), r'}((\d+\.))[ ]+(.*)'])) + self.CHILD_RE = re.compile( + ''.join([r'^[ ]{0,', str(self.tab_length - 1), + r'}((\d+\.))[ ]+(.*)'])) class SaneUListProcessor(UListProcessor): @@ -38,8 +39,9 @@ class SaneUListProcessor(UListProcessor): def __init__(self, parser): UListProcessor.__init__(self, parser) - self.CHILD_RE = re.compile(''.join([ - r'^[ ]{0,', str(self.tab_length - 1), r'}(([*+-]))[ ]+(.*)'])) + self.CHILD_RE = re.compile( + ''.join([r'^[ ]{0,', str(self.tab_length - 1), + r'}(([*+-]))[ ]+(.*)'])) class SaneListExtension(Extension): -- cgit v1.2.3 From d3cc9895fee28161f2537c0cbedf75b89cfd0a89 Mon Sep 17 00:00:00 2001 From: Kar Epker Date: Mon, 1 Jun 2015 18:29:30 -0400 Subject: Changed formatting of regex strings. Fixed flake8 issues. --- markdown/blockprocessors.py | 19 ++++++------------- markdown/extensions/sane_lists.py | 10 ++++------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index 43a384d..d4bb2ac 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -311,18 +311,13 @@ class OListProcessor(BlockProcessor): 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+\.[ ]+(.*)'])) + 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( - ''.join([r'^[ ]{0,', str(self.tab_length - 1), - r'}((\d+\.)|[*+-])[ ]+(.*)'])) + 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( - ''.join([r'^[ ]{', str(self.tab_length), ',', - str(self.tab_length * 2 - 1), - r'}((\d+\.)|[*+-])[ ]+.*'])) + 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)) @@ -421,9 +416,7 @@ class UListProcessor(OListProcessor): 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'}[*+-][ ]+(.*)'])) + self.RE = re.compile(r'^[ ]{0,%d}[*+-][ ]+(.*)' % (self.tab_length - 1)) class HashHeaderProcessor(BlockProcessor): diff --git a/markdown/extensions/sane_lists.py b/markdown/extensions/sane_lists.py index f464ac0..3b2da05 100644 --- a/markdown/extensions/sane_lists.py +++ b/markdown/extensions/sane_lists.py @@ -28,9 +28,8 @@ class SaneOListProcessor(OListProcessor): def __init__(self, parser): OListProcessor.__init__(self, parser) - self.CHILD_RE = re.compile( - ''.join([r'^[ ]{0,', str(self.tab_length - 1), - r'}((\d+\.))[ ]+(.*)'])) + self.CHILD_RE = re.compile(r'^[ ]{0,%d}((\d+\.))[ ]+(.*)' % + (self.tab_length - 1)) class SaneUListProcessor(UListProcessor): @@ -39,9 +38,8 @@ class SaneUListProcessor(UListProcessor): def __init__(self, parser): UListProcessor.__init__(self, parser) - self.CHILD_RE = re.compile( - ''.join([r'^[ ]{0,', str(self.tab_length - 1), - r'}(([*+-]))[ ]+(.*)'])) + self.CHILD_RE = re.compile(r'^[ ]{0,%d}(([*+-]))[ ]+(.*)' % + (self.tab_length - 1)) class SaneListExtension(Extension): -- cgit v1.2.3 From 99257e467eb01d921711c382be4141e97ecb3433 Mon Sep 17 00:00:00 2001 From: Kar Epker Date: Mon, 1 Jun 2015 20:55:37 -0400 Subject: Updated BlockProcessor to new-style class. Changed subclasses to use super(). --- markdown/blockprocessors.py | 8 ++++---- markdown/extensions/sane_lists.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index d4bb2ac..870151b 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -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 @@ -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): @@ -309,7 +309,7 @@ class OListProcessor(BlockProcessor): SIBLING_TAGS = ['ol', 'ul'] def __init__(self, parser): - BlockProcessor.__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. @@ -414,7 +414,7 @@ class UListProcessor(OListProcessor): TAG = 'ul' def __init__(self, parser): - OListProcessor.__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)) diff --git a/markdown/extensions/sane_lists.py b/markdown/extensions/sane_lists.py index 3b2da05..828ae7a 100644 --- a/markdown/extensions/sane_lists.py +++ b/markdown/extensions/sane_lists.py @@ -27,7 +27,7 @@ class SaneOListProcessor(OListProcessor): SIBLING_TAGS = ['ol'] def __init__(self, parser): - OListProcessor.__init__(self, parser) + super(SaneOListProcessor, self).__init__(parser) self.CHILD_RE = re.compile(r'^[ ]{0,%d}((\d+\.))[ ]+(.*)' % (self.tab_length - 1)) @@ -37,7 +37,7 @@ class SaneUListProcessor(UListProcessor): SIBLING_TAGS = ['ul'] def __init__(self, parser): - UListProcessor.__init__(self, parser) + super(SaneUListProcessor, self).__init__(parser) self.CHILD_RE = re.compile(r'^[ ]{0,%d}(([*+-]))[ ]+(.*)' % (self.tab_length - 1)) -- cgit v1.2.3