|
31 | 31 | """
|
32 | 32 |
|
33 | 33 |
|
34 |
| -import re, sys, os, random, codecs |
| 34 | +import re, sys, codecs |
35 | 35 |
|
36 | 36 | from logging import getLogger, StreamHandler, Formatter, \
|
37 | 37 | DEBUG, INFO, WARN, ERROR, CRITICAL
|
@@ -108,7 +108,7 @@ def removeBOM(text, encoding):
|
108 | 108 | 'form', 'fieldset', 'iframe', 'math', 'ins',
|
109 | 109 | 'del', 'hr', 'hr/', 'style']
|
110 | 110 |
|
111 |
| -def is_block_level (tag): |
| 111 | +def isBlockLevel (tag): |
112 | 112 | return ( (tag in BLOCK_LEVEL_ELEMENTS) or
|
113 | 113 | (tag[0] == 'h' and tag[1] in "0123456789") )
|
114 | 114 |
|
@@ -467,7 +467,7 @@ def run (self, lines):
|
467 | 467 | return lines
|
468 | 468 |
|
469 | 469 | 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>""" |
471 | 471 | if block.startswith(" "): return 0 # a code block
|
472 | 472 | text = "".join([x for x in block if not x.isspace()])
|
473 | 473 | if len(text) <= 2:
|
@@ -531,7 +531,7 @@ def run (self, text):
|
531 | 531 | left_tag = self._get_left_tag(block)
|
532 | 532 | right_tag = self._get_right_tag(left_tag, block)
|
533 | 533 |
|
534 |
| - if not (is_block_level(left_tag) \ |
| 534 | + if not (isBlockLevel(left_tag) \ |
535 | 535 | or block[1] in ["!", "?", "@", "%"]):
|
536 | 536 | new_blocks.append(block)
|
537 | 537 | continue
|
@@ -1365,14 +1365,14 @@ def _processHeader(self, parent_elem, paragraph):
|
1365 | 1365 | level = len(m.group(1))
|
1366 | 1366 | h = self.doc.createElement("h%d" % level)
|
1367 | 1367 | parent_elem.appendChild(h)
|
1368 |
| - for item in self._handleInlineWrapper(m.group(2).strip()): |
| 1368 | + for item in self._handleInline(m.group(2).strip()): |
1369 | 1369 | h.appendChild(item)
|
1370 | 1370 | else:
|
1371 | 1371 | message(CRITICAL, "We've got a problem header!")
|
1372 | 1372 |
|
1373 | 1373 |
|
1374 | 1374 | def _processParagraph(self, parent_elem, paragraph, inList, looseList):
|
1375 |
| - list = self._handleInlineWrapper("\n".join(paragraph)) |
| 1375 | + list = self._handleInline("\n".join(paragraph)) |
1376 | 1376 |
|
1377 | 1377 | if ( parent_elem.nodeName == 'li'
|
1378 | 1378 | and not (looseList or parent_elem.childNodes)):
|
@@ -1561,7 +1561,17 @@ def _processCodeBlock(self, parent_elem, lines, inList):
|
1561 | 1561 |
|
1562 | 1562 |
|
1563 | 1563 |
|
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 | + |
1565 | 1575 |
|
1566 | 1576 | parts = [line]
|
1567 | 1577 |
|
@@ -1595,25 +1605,6 @@ def _handleInlineWrapper (self, line, patternIndex=0):
|
1595 | 1605 | return parts
|
1596 | 1606 |
|
1597 | 1607 |
|
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 |
| - |
1617 | 1608 | def _applyPattern(self, line, pattern, patternIndex):
|
1618 | 1609 |
|
1619 | 1610 | """ Given a pattern name, this function checks if the line
|
@@ -1648,7 +1639,7 @@ def _applyPattern(self, line, pattern, patternIndex):
|
1648 | 1639 | for child in node.childNodes:
|
1649 | 1640 | if isinstance(child, TextNode):
|
1650 | 1641 |
|
1651 |
| - result = self._handleInlineWrapper(child.value, patternIndex+1) |
| 1642 | + result = self._handleInline(child.value, patternIndex+1) |
1652 | 1643 |
|
1653 | 1644 | if result:
|
1654 | 1645 |
|
|
0 commit comments