aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2011-06-29 11:32:01 -0400
committerWaylan Limberg <waylan@gmail.com>2011-06-29 11:32:01 -0400
commitd7a91be9a32c3aa539c39d4e801f127ea2cba7fe (patch)
tree3e6f66541aab38bac41f07a349cac3c03fa758d4
parent8761cd1780a7cec6012354f79303f3ea488df7d9 (diff)
downloadmarkdown-d7a91be9a32c3aa539c39d4e801f127ea2cba7fe.tar.gz
markdown-d7a91be9a32c3aa539c39d4e801f127ea2cba7fe.tar.bz2
markdown-d7a91be9a32c3aa539c39d4e801f127ea2cba7fe.zip
Fixed #30. Tables now allow three spaces of indent like PHP Markdown Extra. Thanks to skurfer for report and inital patch.
-rw-r--r--markdown/extensions/tables.py13
-rw-r--r--tests/extensions/extra/tables.html45
-rw-r--r--tests/extensions/extra/tables.txt18
3 files changed, 69 insertions, 7 deletions
diff --git a/markdown/extensions/tables.py b/markdown/extensions/tables.py
index 952fd21..f780bb3 100644
--- a/markdown/extensions/tables.py
+++ b/markdown/extensions/tables.py
@@ -25,20 +25,21 @@ class TableProcessor(markdown.blockprocessors.BlockProcessor):
rows = block.split('\n')
return (len(rows) > 2 and '|' in rows[0] and
'|' in rows[1] and '-' in rows[1] and
- rows[1][0] in ['|', ':', '-'])
+ rows[1].strip()[0] in ['|', ':', '-'])
def run(self, parent, blocks):
""" Parse a table block and build table. """
block = blocks.pop(0).split('\n')
- header = block[:2]
+ header = block[0].strip()
+ seperator = block[1].strip()
rows = block[2:]
# Get format type (bordered by pipes or not)
border = False
- if header[0].startswith('|'):
+ if header.startswith('|'):
border = True
# Get alignment of columns
align = []
- for c in self._split_row(header[1], border):
+ for c in self._split_row(seperator, border):
if c.startswith(':') and c.endswith(':'):
align.append('center')
elif c.startswith(':'):
@@ -50,10 +51,10 @@ class TableProcessor(markdown.blockprocessors.BlockProcessor):
# Build table
table = etree.SubElement(parent, 'table')
thead = etree.SubElement(table, 'thead')
- self._build_row(header[0], thead, align, border)
+ self._build_row(header, thead, align, border)
tbody = etree.SubElement(table, 'tbody')
for row in rows:
- self._build_row(row, tbody, align, border)
+ self._build_row(row.strip(), tbody, align, border)
def _build_row(self, row, parent, align, border):
""" Given a row of text, build table cells. """
diff --git a/tests/extensions/extra/tables.html b/tests/extensions/extra/tables.html
index 1d626da..64196ec 100644
--- a/tests/extensions/extra/tables.html
+++ b/tests/extensions/extra/tables.html
@@ -116,4 +116,47 @@
<td>W</td>
</tr>
</tbody>
-</table> \ No newline at end of file
+</table>
+<p>Three spaces in front of a table:</p>
+<table>
+<thead>
+<tr>
+<th>First Header</th>
+<th>Second Header</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>Content Cell</td>
+<td>Content Cell</td>
+</tr>
+<tr>
+<td>Content Cell</td>
+<td>Content Cell</td>
+</tr>
+</tbody>
+</table>
+<table>
+<thead>
+<tr>
+<th>First Header</th>
+<th>Second Header</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>Content Cell</td>
+<td>Content Cell</td>
+</tr>
+<tr>
+<td>Content Cell</td>
+<td>Content Cell</td>
+</tr>
+</tbody>
+</table>
+<p>Four spaces is a code block:</p>
+<pre><code>First Header | Second Header
+------------ | -------------
+Content Cell | Content Cell
+Content Cell | Content Cell
+</code></pre> \ No newline at end of file
diff --git a/tests/extensions/extra/tables.txt b/tests/extensions/extra/tables.txt
index 64917ab..cf97cb5 100644
--- a/tests/extensions/extra/tables.txt
+++ b/tests/extensions/extra/tables.txt
@@ -32,3 +32,21 @@ foo|bar|baz
| Q |
W | | W
+Three spaces in front of a table:
+
+ First Header | Second Header
+ ------------ | -------------
+ Content Cell | Content Cell
+ Content Cell | Content Cell
+
+ | First Header | Second Header |
+ | ------------ | ------------- |
+ | Content Cell | Content Cell |
+ | Content Cell | Content Cell |
+
+Four spaces is a code block:
+
+ First Header | Second Header
+ ------------ | -------------
+ Content Cell | Content Cell
+ Content Cell | Content Cell