Skip to content

Commit 393ef60

Browse files
author
Waylan Limberg
committed
Just doing a little code cleanup.
1 parent eea2ee0 commit 393ef60

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

markdown.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"""
3232

3333

34-
import re, sys, os, random, codecs
34+
import re, sys, codecs
3535

3636
from logging import getLogger, StreamHandler, Formatter, \
3737
DEBUG, INFO, WARN, ERROR, CRITICAL
@@ -108,7 +108,7 @@ def removeBOM(text, encoding):
108108
'form', 'fieldset', 'iframe', 'math', 'ins',
109109
'del', 'hr', 'hr/', 'style']
110110

111-
def is_block_level (tag):
111+
def isBlockLevel (tag):
112112
return ( (tag in BLOCK_LEVEL_ELEMENTS) or
113113
(tag[0] == 'h' and tag[1] in "0123456789") )
114114

@@ -467,7 +467,7 @@ def run (self, lines):
467467
return lines
468468

469469
def _isLine(self, block):
470-
"""Determines if a block should be replaced with an <:wHR>"""
470+
"""Determines if a block should be replaced with an <HR>"""
471471
if block.startswith(" "): return 0 # a code block
472472
text = "".join([x for x in block if not x.isspace()])
473473
if len(text) <= 2:
@@ -531,7 +531,7 @@ def run (self, text):
531531
left_tag = self._get_left_tag(block)
532532
right_tag = self._get_right_tag(left_tag, block)
533533

534-
if not (is_block_level(left_tag) \
534+
if not (isBlockLevel(left_tag) \
535535
or block[1] in ["!", "?", "@", "%"]):
536536
new_blocks.append(block)
537537
continue
@@ -1365,14 +1365,14 @@ def _processHeader(self, parent_elem, paragraph):
13651365
level = len(m.group(1))
13661366
h = self.doc.createElement("h%d" % level)
13671367
parent_elem.appendChild(h)
1368-
for item in self._handleInlineWrapper(m.group(2).strip()):
1368+
for item in self._handleInline(m.group(2).strip()):
13691369
h.appendChild(item)
13701370
else:
13711371
message(CRITICAL, "We've got a problem header!")
13721372

13731373

13741374
def _processParagraph(self, parent_elem, paragraph, inList, looseList):
1375-
list = self._handleInlineWrapper("\n".join(paragraph))
1375+
list = self._handleInline("\n".join(paragraph))
13761376

13771377
if ( parent_elem.nodeName == 'li'
13781378
and not (looseList or parent_elem.childNodes)):
@@ -1561,7 +1561,17 @@ def _processCodeBlock(self, parent_elem, lines, inList):
15611561

15621562

15631563

1564-
def _handleInlineWrapper (self, line, patternIndex=0):
1564+
def _handleInline (self, line, patternIndex=0):
1565+
"""Transform a Markdown line with inline elements to an XHTML
1566+
fragment.
1567+
1568+
This function uses auxiliary objects called inline patterns.
1569+
See notes on inline patterns above.
1570+
1571+
@param line: A line of Markdown text
1572+
@param patternIndex: The index of the inlinePattern to start with
1573+
@return: A list of NanoDom nodes """
1574+
15651575

15661576
parts = [line]
15671577

@@ -1595,25 +1605,6 @@ def _handleInlineWrapper (self, line, patternIndex=0):
15951605
return parts
15961606

15971607

1598-
def _handleInline(self, line):
1599-
"""Transform a Markdown line with inline elements to an XHTML
1600-
fragment.
1601-
1602-
This function uses auxiliary objects called inline patterns.
1603-
See notes on inline patterns above.
1604-
1605-
@param item: A block of Markdown text
1606-
@return: A list of NanoDom nodes """
1607-
1608-
if not(line):
1609-
return [self.doc.createTextNode(' ')]
1610-
1611-
for pattern in self.inlinePatterns:
1612-
list = self._applyPattern( line, pattern)
1613-
if list: return list
1614-
1615-
return [self.doc.createTextNode(line)]
1616-
16171608
def _applyPattern(self, line, pattern, patternIndex):
16181609

16191610
""" Given a pattern name, this function checks if the line
@@ -1648,7 +1639,7 @@ def _applyPattern(self, line, pattern, patternIndex):
16481639
for child in node.childNodes:
16491640
if isinstance(child, TextNode):
16501641

1651-
result = self._handleInlineWrapper(child.value, patternIndex+1)
1642+
result = self._handleInline(child.value, patternIndex+1)
16521643

16531644
if result:
16541645

0 commit comments

Comments
 (0)