diff --git a/src/extensions/table.js b/src/extensions/table.js
index faa9659..84c20dd 100644
--- a/src/extensions/table.js
+++ b/src/extensions/table.js
@@ -11,62 +11,94 @@
* |**bold** | ![Valid XHTML] (http://w3.org/Icons/valid-xhtml10) |
* | Plain | Value |
*
+ *
+ *
+ * | Col 1 | Col 2|
+ * |:========:|===================================================:|
+ * | col 1 | is center aligned|
+ * | col 2 | is right aligned|
+ *
*/
(function(){
var table = function(converter) {
- var tables = {}, style = 'text-align:left;', filter;
- tables.th = function(header){
+ var tables = {}, filter;
+ tables.th = function(header, style) {
if (header.trim() === "") { return "";}
var id = header.trim().replace(/ /g, '_').toLowerCase();
- return '
' + header + ' | ';
+ return '' + header + ' | ';
};
- tables.td = function(cell) {
- return '' + converter.makeHtml(cell) + ' | ';
+ tables.td = function(cell, style) {
+ return '' + converter.makeHtml(cell) + ' | ';
};
- tables.ths = function(){
- var out = "", i = 0, hs = [].slice.apply(arguments);
+ tables.ths = function() {
+ var out = "", i = 0, hs = [].slice.apply(arguments[0]), style = [].slice.apply(arguments[1]);
for (i;i\n";
- out += tables.ths.apply(this, hs);
+ out += tables.ths.apply(this, [hs, style]);
out += "\n";
out += "\n";
return out;
};
tables.tr = function() {
- var out, i = 0, cs = [].slice.apply(arguments);
+ var out, i = 0, cs = [].slice.apply(arguments[0]), style = [].slice.apply(arguments[1]);
out = "\n";
- out += tables.tds.apply(this, cs);
+ out += tables.tds.apply(this, [cs, style]);
out += "
\n";
return out;
};
filter = function(text) {
var i=0, lines = text.split('\n'), line, hs, rows, out = [];
- for (i; i');
hs = line.substring(1, line.length -1).split('|');
- tbl.push(tables.thead.apply(this, hs));
+ if (styles.length === 0) {
+ var j=0;
+ for (j;j');
while (line.trim().match(/^[|]{1}.*[|]{1}$/)) {
line = line.trim();
- tbl.push(tables.tr.apply(this, line.substring(1, line.length -1).split('|')));
+ tbl.push(tables.tr.apply(this, [line.substring(1, line.length -1).split('|'), styles]));
line = lines[++i];
}
tbl.push('');
diff --git a/test/extensions/table/basic.html b/test/extensions/table/basic.html
index d909e65..131e66b 100644
--- a/test/extensions/table/basic.html
+++ b/test/extensions/table/basic.html
@@ -2,19 +2,19 @@
-
+
Row 1 Cell 1 |
-Row 1 Cell 2 |
+Row 1 Cell 2 |
Row 2 Cell 1 |
-Row 2 Cell 2 |
+Row 2 Cell 2 |
diff --git a/test/extensions/table/basic.md b/test/extensions/table/basic.md
index d67f8fd..481d94b 100644
--- a/test/extensions/table/basic.md
+++ b/test/extensions/table/basic.md
@@ -1,4 +1,4 @@
| First Header | Second Header |
-| ------------- | ------------- |
+| ------------- |: ----------- :|
| Row 1 Cell 1 | Row 1 Cell 2 |
| Row 2 Cell 1 | Row 2 Cell 2 |
diff --git a/test/extensions/table/large.html b/test/extensions/table/large.html
index 332bdab..bd6fa7a 100644
--- a/test/extensions/table/large.html
+++ b/test/extensions/table/large.html
@@ -2,8 +2,8 @@
-
-
+
+
@@ -11,36 +11,36 @@
Row 1 Cell 1 |
-Row 1 Cell 2 |
-Row 1 Cell 3 |
+Row 1 Cell 2 |
+Row 1 Cell 3 |
Row 1 Cell 4 |
Row 2 Cell 1 |
-Row 2 Cell 2 |
-Row 2 Cell 3 |
+Row 2 Cell 2 |
+Row 2 Cell 3 |
Row 2 Cell 4 |
Row 3 Cell 1 |
-Row 3 Cell 2 |
-Row 3 Cell 3 |
+Row 3 Cell 2 |
+Row 3 Cell 3 |
Row 3 Cell 4 |
Row 4 Cell 1 |
-Row 4 Cell 2 |
-Row 4 Cell 3 |
+Row 4 Cell 2 |
+Row 4 Cell 3 |
Row 4 Cell 4 |
Row 5 Cell 1 |
-Row 5 Cell 2 |
-Row 5 Cell 3 |
+Row 5 Cell 2 |
+Row 5 Cell 3 |
Row 5 Cell 4 |
diff --git a/test/extensions/table/large.md b/test/extensions/table/large.md
index e18e478..6f6c692 100644
--- a/test/extensions/table/large.md
+++ b/test/extensions/table/large.md
@@ -1,5 +1,5 @@
| First Header | Second Header | Third Header | Fourth Header |
-| ------------- | ------------- | ------------ | ------------- |
+| ------------- |: ----------- :| ------------ :| ------------- |
| Row 1 Cell 1 | Row 1 Cell 2 | Row 1 Cell 3 | Row 1 Cell 4 |
| Row 2 Cell 1 | Row 2 Cell 2 | Row 2 Cell 3 | Row 2 Cell 4 |
| Row 3 Cell 1 | Row 3 Cell 2 | Row 3 Cell 3 | Row 3 Cell 4 |
diff --git a/test/extensions/table/with-equals.html b/test/extensions/table/with-equals.html
index d909e65..131e66b 100644
--- a/test/extensions/table/with-equals.html
+++ b/test/extensions/table/with-equals.html
@@ -2,19 +2,19 @@
-
+
Row 1 Cell 1 |
-Row 1 Cell 2 |
+Row 1 Cell 2 |
Row 2 Cell 1 |
-Row 2 Cell 2 |
+Row 2 Cell 2 |
diff --git a/test/extensions/table/with-equals.md b/test/extensions/table/with-equals.md
index 744a6db..e6e5e72 100644
--- a/test/extensions/table/with-equals.md
+++ b/test/extensions/table/with-equals.md
@@ -1,4 +1,4 @@
| First Header | Second Header |
-| ============= | ============= |
+|:============= |:=============:|
| Row 1 Cell 1 | Row 1 Cell 2 |
| Row 2 Cell 1 | Row 2 Cell 2 |
diff --git a/test/extensions/table/with-surroundings.html b/test/extensions/table/with-surroundings.html
index a8957c3..0719d1e 100644
--- a/test/extensions/table/with-surroundings.html
+++ b/test/extensions/table/with-surroundings.html
@@ -6,20 +6,23 @@ vulputate dictum. Vestibulum consequat ultricies nibh, sed tempus nisl mattis a.
-
+
+
-Row 1 Cell 1 |
+Row 1 Cell 1 |
Row 1 Cell 2 |
+Row 1 Cell 3 |
-Row 2 Cell 1 |
+Row 2 Cell 1 |
Row 2 Cell 2 |
+Row 2 Cell 3 |
diff --git a/test/extensions/table/with-surroundings.md b/test/extensions/table/with-surroundings.md
index b55baa3..8e55db8 100644
--- a/test/extensions/table/with-surroundings.md
+++ b/test/extensions/table/with-surroundings.md
@@ -3,10 +3,10 @@ ullamcorper euismod iaculis sed, tristique at neque. Nullam metus risus,
malesuada vitae imperdiet ac, tincidunt eget lacus. Proin ullamcorper
vulputate dictum. Vestibulum consequat ultricies nibh, sed tempus nisl mattis a.
-| First Header | Second Header |
-| ------------- | ------------- |
-| Row 1 Cell 1 | Row 1 Cell 2 |
-| Row 2 Cell 1 | Row 2 Cell 2 |
+| First Header | Second Header | Third Header |
+| ------------: | ------------- | :-----------: |
+| Row 1 Cell 1 | Row 1 Cell 2 | Row 1 Cell 3 |
+| Row 2 Cell 1 | Row 2 Cell 2 | Row 2 Cell 3 |
Phasellus ac porttitor quam. Integer cursus accumsan mauris nec interdum.
Etiam iaculis urna vitae risus facilisis faucibus eu quis risus. Sed aliquet
diff --git a/test/extensions/table/without-body.html b/test/extensions/table/without-body.html
index 5b37e4a..facc2f9 100644
--- a/test/extensions/table/without-body.html
+++ b/test/extensions/table/without-body.html
@@ -1,7 +1,7 @@
-
+
diff --git a/test/extensions/table/without-body.md b/test/extensions/table/without-body.md
index 78c06f0..9c11d5c 100644
--- a/test/extensions/table/without-body.md
+++ b/test/extensions/table/without-body.md
@@ -1,2 +1,2 @@
| First Header | Second Header |
-| ------------- | ------------- |
+| ------------ :| ------------- |