diff options
Diffstat (limited to 'markdown/extensions/tables.py')
-rw-r--r-- | markdown/extensions/tables.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/markdown/extensions/tables.py b/markdown/extensions/tables.py index 57507e9..cbf711a 100644 --- a/markdown/extensions/tables.py +++ b/markdown/extensions/tables.py @@ -4,7 +4,7 @@ Tables Extension for Python-Markdown Added parsing of tables to Python-Markdown. -See <https://pythonhosted.org/Markdown/extensions/tables.html> +See <https://pythonhosted.org/Markdown/extensions/tables.html> for documentation. Original code Copyright 2009 [Waylan Limberg](http://achinghead.com) @@ -21,13 +21,14 @@ from . import Extension from ..blockprocessors import BlockProcessor from ..util import etree + class TableProcessor(BlockProcessor): """ Process Tables. """ def test(self, parent, block): rows = block.split('\n') - return (len(rows) > 2 and '|' in rows[0] and - '|' in rows[1] and '-' in rows[1] and + return (len(rows) > 2 and '|' in rows[0] and + '|' in rows[1] and '-' in rows[1] and rows[1].strip()[0] in ['|', ':', '-']) def run(self, parent, blocks): @@ -66,13 +67,13 @@ class TableProcessor(BlockProcessor): if parent.tag == 'thead': tag = 'th' cells = self._split_row(row, border) - # We use align here rather than cells to ensure every row + # We use align here rather than cells to ensure every row # contains the same number of columns. for i, a in enumerate(align): c = etree.SubElement(tr, tag) try: c.text = cells[i].strip() - except IndexError: #pragma: no cover + except IndexError: # pragma: no cover c.text = "" if a: c.set('align', a) @@ -92,11 +93,10 @@ class TableExtension(Extension): def extendMarkdown(self, md, md_globals): """ Add an instance of TableProcessor to BlockParser. """ - md.parser.blockprocessors.add('table', + md.parser.blockprocessors.add('table', TableProcessor(md.parser), '<hashheader') def makeExtension(*args, **kwargs): return TableExtension(*args, **kwargs) - |