diff options
author | Toshio Kuratomi <toshio@fedoraproject.org> | 2010-07-05 22:53:31 -0400 |
---|---|---|
committer | Toshio Kuratomi <toshio@fedoraproject.org> | 2010-07-05 22:53:31 -0400 |
commit | 2eb00c816c6dc31dbbec6c47f8c7ff70ed0785d2 (patch) | |
tree | 53024beda5d31143da2a2a0a2e81fa48ca29ba14 /markdown/blockprocessors.py | |
parent | a91f766c57d67cebbfc35020f89016ceb4358926 (diff) | |
download | markdown-2eb00c816c6dc31dbbec6c47f8c7ff70ed0785d2.tar.gz markdown-2eb00c816c6dc31dbbec6c47f8c7ff70ed0785d2.tar.bz2 markdown-2eb00c816c6dc31dbbec6c47f8c7ff70ed0785d2.zip |
Rename misc.py to util.py at the request of upstream
Diffstat (limited to 'markdown/blockprocessors.py')
-rw-r--r-- | markdown/blockprocessors.py | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index 3aeef34..6e1f146 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -13,7 +13,7 @@ as they need to alter how markdown blocks are parsed. """ import re -import misc +import util from misc_logging import CRITICAL, message class BlockProcessor: @@ -42,8 +42,8 @@ class BlockProcessor: newtext = [] lines = text.split('\n') for line in lines: - if line.startswith(' '*misc.TAB_LENGTH): - newtext.append(line[misc.TAB_LENGTH:]) + if line.startswith(' '*util.TAB_LENGTH): + newtext.append(line[util.TAB_LENGTH:]) elif not line.strip(): newtext.append('') else: @@ -54,8 +54,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(' '*misc.TAB_LENGTH*level): - lines[i] = lines[i][misc.TAB_LENGTH*level:] + if lines[i].startswith(' '*util.TAB_LENGTH*level): + lines[i] = lines[i][util.TAB_LENGTH*level:] return '\n'.join(lines) def test(self, parent, block): @@ -114,12 +114,12 @@ class ListIndentProcessor(BlockProcessor): """ - INDENT_RE = re.compile(r'^(([ ]{%s})+)'% misc.TAB_LENGTH) + INDENT_RE = re.compile(r'^(([ ]{%s})+)'% util.TAB_LENGTH) ITEM_TYPES = ['li'] LIST_TYPES = ['ul', 'ol'] def test(self, parent, block): - return block.startswith(' '*misc.TAB_LENGTH) and \ + return block.startswith(' '*util.TAB_LENGTH) and \ not self.parser.state.isstate('detabbed') and \ (parent.tag in self.ITEM_TYPES or \ (len(parent) and parent[-1] and \ @@ -154,7 +154,7 @@ class ListIndentProcessor(BlockProcessor): # If the parent li has text, that text needs to be moved to a p # The p must be 'inserted' at beginning of list in the event # that other children already exist i.e.; a nested sublist. - p = misc.etree.Element('p') + p = util.etree.Element('p') p.text = sibling[-1].text sibling[-1].text = '' sibling[-1].insert(0, p) @@ -165,7 +165,7 @@ class ListIndentProcessor(BlockProcessor): def create_item(self, parent, block): """ Create a new li and parse the block with it as the parent. """ - li = misc.etree.SubElement(parent, 'li') + li = util.etree.SubElement(parent, 'li') self.parser.parseBlocks(li, [block]) def get_level(self, parent, block): @@ -173,7 +173,7 @@ class ListIndentProcessor(BlockProcessor): # Get indent level m = self.INDENT_RE.match(block) if m: - indent_level = len(m.group(1))/misc.TAB_LENGTH + indent_level = len(m.group(1))/util.TAB_LENGTH else: indent_level = 0 if self.parser.state.isstate('list'): @@ -200,7 +200,7 @@ class CodeBlockProcessor(BlockProcessor): """ Process code blocks. """ def test(self, parent, block): - return block.startswith(' '*misc.TAB_LENGTH) + return block.startswith(' '*util.TAB_LENGTH) def run(self, parent, blocks): sibling = self.lastChild(parent) @@ -213,13 +213,13 @@ class CodeBlockProcessor(BlockProcessor): # linebreaks removed from the split into a list. code = sibling[0] block, theRest = self.detab(block) - code.text = misc.AtomicString('%s\n%s\n' % (code.text, block.rstrip())) + code.text = util.AtomicString('%s\n%s\n' % (code.text, block.rstrip())) else: # This is a new codeblock. Create the elements and insert text. - pre = misc.etree.SubElement(parent, 'pre') - code = misc.etree.SubElement(pre, 'code') + pre = util.etree.SubElement(parent, 'pre') + code = util.etree.SubElement(pre, 'code') block, theRest = self.detab(block) - code.text = misc.AtomicString('%s\n' % block.rstrip()) + code.text = util.AtomicString('%s\n' % block.rstrip()) if theRest: # This block contained unindented line(s) after the first indented # line. Insert these lines as the first block of the master blocks @@ -250,7 +250,7 @@ class BlockQuoteProcessor(BlockProcessor): quote = sibling else: # This is a new blockquote. Create a new parent element. - quote = misc.etree.SubElement(parent, 'blockquote') + quote = util.etree.SubElement(parent, 'blockquote') # Recursively parse block with blockquote as parent. # change parser state so blockquotes embedded in lists use p tags self.parser.state.set('blockquote') @@ -295,13 +295,13 @@ class OListProcessor(BlockProcessor): # since it's possible there are other children for this sibling, # we can't just SubElement the p, we need to insert it as the # first item - p = misc.etree.Element('p') + p = util.etree.Element('p') p.text = lst[-1].text lst[-1].text = '' lst[-1].insert(0, p) # parse first block differently as it gets wrapped in a p. - li = misc.etree.SubElement(lst, 'li') + li = util.etree.SubElement(lst, 'li') self.parser.state.set('looselist') firstitem = items.pop(0) self.parser.parseBlocks(li, [firstitem]) @@ -315,17 +315,17 @@ class OListProcessor(BlockProcessor): lst = parent else: # This is a new list so create parent with appropriate tag. - lst = misc.etree.SubElement(parent, self.TAG) + lst = util.etree.SubElement(parent, self.TAG) self.parser.state.set('list') # Loop through items in block, recursively parsing each with the # appropriate parent. for item in items: - if item.startswith(' '*misc.TAB_LENGTH): + if item.startswith(' '*util.TAB_LENGTH): # Item is indented. Parse with last item as parent self.parser.parseBlocks(lst[-1], [item]) else: # New item. Create li and parse with it as parent - li = misc.etree.SubElement(lst, 'li') + li = util.etree.SubElement(lst, 'li') self.parser.parseBlocks(li, [item]) self.parser.state.reset() @@ -339,7 +339,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(' '*misc.TAB_LENGTH): + if items[-1].startswith(' '*util.TAB_LENGTH): # Previous item was indented. Append to that item. items[-1] = '%s\n%s' % (items[-1], line) else: @@ -378,7 +378,7 @@ class HashHeaderProcessor(BlockProcessor): # recursively parse this lines as a block. self.parser.parseBlocks(parent, [before]) # Create header using named groups from RE - h = misc.etree.SubElement(parent, 'h%d' % len(m.group('level'))) + h = util.etree.SubElement(parent, 'h%d' % len(m.group('level'))) h.text = m.group('header').strip() if after: # Insert remaining lines as first block for future parsing. @@ -404,7 +404,7 @@ class SetextHeaderProcessor(BlockProcessor): level = 1 else: level = 2 - h = misc.etree.SubElement(parent, 'h%d' % level) + h = util.etree.SubElement(parent, 'h%d' % level) h.text = lines[0].strip() if len(lines) > 2: # Block contains additional lines. Add to master blocks for later. @@ -437,7 +437,7 @@ class HRProcessor(BlockProcessor): # Recursively parse lines before hr so they get parsed first. self.parser.parseBlocks(parent, ['\n'.join(prelines)]) # create hr - hr = misc.etree.SubElement(parent, 'hr') + hr = util.etree.SubElement(parent, 'hr') # check for lines in block after hr. lines = lines[len(prelines)+1:] if len(lines): @@ -465,7 +465,7 @@ class EmptyBlockProcessor(BlockProcessor): if sibling and sibling.tag == 'pre' and sibling[0] and \ sibling[0].tag == 'code': # Last block is a codeblock. Append to preserve whitespace. - sibling[0].text = misc.AtomicString('%s/n/n/n' % sibling[0].text ) + sibling[0].text = util.AtomicString('%s/n/n/n' % sibling[0].text ) class ParagraphProcessor(BlockProcessor): @@ -486,5 +486,5 @@ class ParagraphProcessor(BlockProcessor): parent.text = block.lstrip() else: # Create a regular paragraph - p = misc.etree.SubElement(parent, 'p') + p = util.etree.SubElement(parent, 'p') p.text = block.lstrip() |