diff --git a/Parsedown.php b/Parsedown.php
index a9702af..a56ae6e 100755
--- a/Parsedown.php
+++ b/Parsedown.php
@@ -293,6 +293,59 @@ class Parsedown
break;
+ case 'table':
+
+ if ($line === '')
+ {
+ $context = null;
+
+ continue 2;
+ }
+
+ if ($line[0] === '|')
+ {
+ $nested_blocks = array();
+
+ $substring = preg_replace('/^[|][ ]*/', '', $line);
+ $substring = preg_replace('/[|]?[ ]*$/', '', $substring);
+
+ $parts = explode('|', $substring);
+
+ foreach ($parts as $index => $part)
+ {
+ $substring = trim($part);
+
+ $nested_block = array(
+ 'name' => 'td',
+ 'content type' => 'markdown',
+ 'content' => $substring,
+ );
+
+ if (isset($context_data['alignments'][$index]))
+ {
+ $nested_block['attributes'] = array(
+ 'align' => $context_data['alignments'][$index],
+ );
+ }
+
+ $nested_blocks []= $nested_block;
+ }
+
+ $nested_block = array(
+ 'name' => 'tr',
+ 'content type' => 'blocks',
+ 'content' => $nested_blocks,
+ );
+
+ $block['content'][1]['content'] []= $nested_block;
+
+ continue 2;
+ }
+
+ $context = null;
+
+ break;
+
case 'paragraph':
if ($line === '')
@@ -322,6 +375,105 @@ class Parsedown
continue 2;
}
+ if ($line[0] === '|' and $block['content'][0] === '|' and chop($line, ' -:|') === '')
+ {
+ $values = array();
+
+ $substring = trim($line, ' |');
+
+ $parts = explode('|', $substring);
+
+ foreach ($parts as $part)
+ {
+ $substring = trim($part);
+
+ $value = null;
+
+ if ($substring[0] === ':')
+ {
+ $value = 'left';
+ }
+
+ if (substr($substring, -1) === ':')
+ {
+ $value = $value === 'left' ? 'center' : 'right';
+ }
+
+ $values []= $value;
+ }
+
+ # ~
+
+ $nested_blocks = array();
+
+ $substring = preg_replace('/^[|][ ]*/', '', $block['content']);
+ $substring = preg_replace('/[|]?[ ]*$/', '', $substring);
+
+ $parts = explode('|', $substring);
+
+ foreach ($parts as $index => $part)
+ {
+ $substring = trim($part);
+
+ $nested_block = array(
+ 'name' => 'th',
+ 'content type' => 'markdown',
+ 'content' => $substring,
+ );
+
+ if (isset($values[$index]))
+ {
+ $value = $values[$index];
+
+ $nested_block['attributes'] = array(
+ 'align' => $value,
+ );
+ }
+
+ $nested_blocks []= $nested_block;
+ }
+
+ # ~
+
+ $block = array(
+ 'name' => 'table',
+ 'content type' => 'blocks',
+ 'content' => array(),
+ );
+
+ $block['content'] []= array(
+ 'name' => 'thead',
+ 'content type' => 'blocks',
+ 'content' => array(),
+ );
+
+ $block['content'] []= array(
+ 'name' => 'tbody',
+ 'content type' => 'blocks',
+ 'content' => array(),
+ );
+
+ $block['content'][0]['content'] []= array(
+ 'name' => 'tr',
+ 'content type' => 'blocks',
+ 'content' => array(),
+ );
+
+ $block['content'][0]['content'][0]['content'] = $nested_blocks;
+
+ # ~
+
+ $context = 'table';
+
+ $context_data = array(
+ 'alignments' => $values,
+ );
+
+ # ~
+
+ continue 2;
+ }
+
break;
default:
diff --git a/tests/data/aligned_table.html b/tests/data/aligned_table.html
new file mode 100644
index 0000000..0657bd1
--- /dev/null
+++ b/tests/data/aligned_table.html
@@ -0,0 +1,21 @@
+
+
+
+header 1 |
+header 2 |
+header 2 |
+
+
+
+
+cell 1.1 |
+cell 1.2 |
+cell 1.3 |
+
+
+cell 2.1 |
+cell 2.2 |
+cell 2.3 |
+
+
+
\ No newline at end of file
diff --git a/tests/data/aligned_table.md b/tests/data/aligned_table.md
new file mode 100644
index 0000000..69a45f9
--- /dev/null
+++ b/tests/data/aligned_table.md
@@ -0,0 +1,4 @@
+| header 1 | header 2 | header 2 |
+| :------- | :------: | -------: |
+| cell 1.1 | cell 1.2 | cell 1.3 |
+| cell 2.1 | cell 2.2 | cell 2.3 |
\ No newline at end of file
diff --git a/tests/data/simple_table.html b/tests/data/simple_table.html
new file mode 100644
index 0000000..88e1c2b
--- /dev/null
+++ b/tests/data/simple_table.html
@@ -0,0 +1,18 @@
+
+
+
+header 1 |
+header 2 |
+
+
+
+
+cell 1.1 |
+cell 1.2 |
+
+
+cell 2.1 |
+cell 2.2 |
+
+
+
\ No newline at end of file
diff --git a/tests/data/simple_table.md b/tests/data/simple_table.md
new file mode 100644
index 0000000..5245e6c
--- /dev/null
+++ b/tests/data/simple_table.md
@@ -0,0 +1,4 @@
+| header 1 | header 2 |
+| -------- | -------- |
+| cell 1.1 | cell 1.2 |
+| cell 2.1 | cell 2.2 |
\ No newline at end of file
diff --git a/tests/data/table_inline_markdown.html b/tests/data/table_inline_markdown.html
new file mode 100644
index 0000000..53d0eb8
--- /dev/null
+++ b/tests/data/table_inline_markdown.html
@@ -0,0 +1,18 @@
+
+
+
+header 1 |
+header 2 |
+
+
+
+
+cell 1.1 |
+cell 1.2 |
+
+
+cell 2.1 |
+cell 2.2 |
+
+
+
\ No newline at end of file
diff --git a/tests/data/table_inline_markdown.md b/tests/data/table_inline_markdown.md
new file mode 100644
index 0000000..c2fe108
--- /dev/null
+++ b/tests/data/table_inline_markdown.md
@@ -0,0 +1,4 @@
+| _header_ 1 | header 2 |
+| ------------ | ------------ |
+| _cell_ 1.1 | ~~cell~~ 1.2 |
+| `cell` 2.1 | cell 2.2 |
\ No newline at end of file
diff --git a/tests/data/untidy_table.html b/tests/data/untidy_table.html
new file mode 100644
index 0000000..88e1c2b
--- /dev/null
+++ b/tests/data/untidy_table.html
@@ -0,0 +1,18 @@
+
+
+
+header 1 |
+header 2 |
+
+
+
+
+cell 1.1 |
+cell 1.2 |
+
+
+cell 2.1 |
+cell 2.2 |
+
+
+
\ No newline at end of file
diff --git a/tests/data/untidy_table.md b/tests/data/untidy_table.md
new file mode 100644
index 0000000..8524eb1
--- /dev/null
+++ b/tests/data/untidy_table.md
@@ -0,0 +1,4 @@
+| header 1 | header 2 |
+| ------------- | ----------- |
+| cell 1.1 | cell 1.2 |
+| cell 2.1 | cell 2.2 |
\ No newline at end of file