aboutsummaryrefslogtreecommitdiffstats
path: root/markdown/blockprocessors.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2010-07-07 11:50:41 -0400
committerWaylan Limberg <waylan@gmail.com>2010-07-07 11:50:41 -0400
commit9b1de64b9e4a049f3fd5c9efc343f0e37f7ce457 (patch)
tree7e37c4df91f008c0dbf58718d15a955b9d4b376d /markdown/blockprocessors.py
parenta33a04439905851b5b1a5db4104ec3a11b4ab1d3 (diff)
downloadmarkdown-9b1de64b9e4a049f3fd5c9efc343f0e37f7ce457.tar.gz
markdown-9b1de64b9e4a049f3fd5c9efc343f0e37f7ce457.tar.bz2
markdown-9b1de64b9e4a049f3fd5c9efc343f0e37f7ce457.zip
A better implementation of globals as attributes on the Markdown class. This should be more future proof.
Diffstat (limited to 'markdown/blockprocessors.py')
-rw-r--r--markdown/blockprocessors.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py
index 399a523..77fbc71 100644
--- a/markdown/blockprocessors.py
+++ b/markdown/blockprocessors.py
@@ -48,7 +48,7 @@ class BlockProcessor:
def __init__(self, parser):
self.parser = parser
- self.TAB_LENGTH = parser.markdown.TAB_LENGTH
+ self.tab_length = parser.markdown.tab_length
def lastChild(self, parent):
""" Return the last child of an etree element. """
@@ -62,8 +62,8 @@ class BlockProcessor:
newtext = []
lines = text.split('\n')
for line in lines:
- if line.startswith(' '*self.TAB_LENGTH):
- newtext.append(line[self.TAB_LENGTH:])
+ if line.startswith(' '*self.tab_length):
+ newtext.append(line[self.tab_length:])
elif not line.strip():
newtext.append('')
else:
@@ -74,8 +74,8 @@ class BlockProcessor:
""" Remove a tab from front of lines but allowing dedented lines. """
lines = text.split('\n')
for i in range(len(lines)):
- if lines[i].startswith(' '*self.TAB_LENGTH*level):
- lines[i] = lines[i][self.TAB_LENGTH*level:]
+ if lines[i].startswith(' '*self.tab_length*level):
+ lines[i] = lines[i][self.tab_length*level:]
return '\n'.join(lines)
def test(self, parent, block):
@@ -139,10 +139,10 @@ class ListIndentProcessor(BlockProcessor):
def __init__(self, *args):
BlockProcessor.__init__(self, *args)
- self.INDENT_RE = re.compile(r'^(([ ]{%s})+)'% self.TAB_LENGTH)
+ self.INDENT_RE = re.compile(r'^(([ ]{%s})+)'% self.tab_length)
def test(self, parent, block):
- return block.startswith(' '*self.TAB_LENGTH) and \
+ return block.startswith(' '*self.tab_length) and \
not self.parser.state.isstate('detabbed') and \
(parent.tag in self.ITEM_TYPES or \
(len(parent) and parent[-1] and \
@@ -196,7 +196,7 @@ class ListIndentProcessor(BlockProcessor):
# Get indent level
m = self.INDENT_RE.match(block)
if m:
- indent_level = len(m.group(1))/self.TAB_LENGTH
+ indent_level = len(m.group(1))/self.tab_length
else:
indent_level = 0
if self.parser.state.isstate('list'):
@@ -223,7 +223,7 @@ class CodeBlockProcessor(BlockProcessor):
""" Process code blocks. """
def test(self, parent, block):
- return block.startswith(' '*self.TAB_LENGTH)
+ return block.startswith(' '*self.tab_length)
def run(self, parent, blocks):
sibling = self.lastChild(parent)
@@ -343,7 +343,7 @@ class OListProcessor(BlockProcessor):
# Loop through items in block, recursively parsing each with the
# appropriate parent.
for item in items:
- if item.startswith(' '*self.TAB_LENGTH):
+ if item.startswith(' '*self.tab_length):
# Item is indented. Parse with last item as parent
self.parser.parseBlocks(lst[-1], [item])
else:
@@ -362,7 +362,7 @@ class OListProcessor(BlockProcessor):
items.append(m.group(3))
elif self.INDENT_RE.match(line):
# This is an indented (possibly nested) item.
- if items[-1].startswith(' '*self.TAB_LENGTH):
+ if items[-1].startswith(' '*self.tab_length):
# Previous item was indented. Append to that item.
items[-1] = '%s\n%s' % (items[-1], line)
else: