Added fix to prevent table rendering to be broken by alignment character ":".

This commit is contained in:
Alessandro Vermeulen 2015-01-09 21:32:05 +01:00
parent bd242722bb
commit 3dbc6ffcfb
3 changed files with 31 additions and 6 deletions

View File

@ -15,7 +15,7 @@
(function(){ (function(){
var table = function(converter) { var table = function(converter) {
var tables = {}, style = 'text-align:left;', filter; var tables = {}, style = 'text-align:left;', filter;
tables.th = function(header){ tables.th = function(header){
if (header.trim() === "") { return "";} if (header.trim() === "") { return "";}
var id = header.trim().replace(/ /g, '_').toLowerCase(); var id = header.trim().replace(/ /g, '_').toLowerCase();
@ -54,7 +54,7 @@
out += "</tr>\n"; out += "</tr>\n";
return out; return out;
}; };
filter = function(text) { filter = function(text) {
var i=0, lines = text.split('\n'), line, hs, rows, out = []; var i=0, lines = text.split('\n'), line, hs, rows, out = [];
for (i; i<lines.length;i+=1) { for (i; i<lines.length;i+=1) {
line = lines[i]; line = lines[i];
@ -66,7 +66,7 @@
hs = line.substring(1, line.length -1).split('|'); hs = line.substring(1, line.length -1).split('|');
tbl.push(tables.thead.apply(this, hs)); tbl.push(tables.thead.apply(this, hs));
line = lines[++i]; line = lines[++i];
if (!line.trim().match(/^[|]{1}[-=| ]+[|]{1}$/)) { if (!line.trim().match(/^[|]{1}[-=|: ]+[|]{1}$/)) {
// not a table rolling back // not a table rolling back
line = lines[--i]; line = lines[--i];
} }
@ -86,12 +86,12 @@
} }
} }
out.push(line); out.push(line);
} }
return out.join('\n'); return out.join('\n');
}; };
return [ return [
{ {
type: 'lang', type: 'lang',
filter: filter filter: filter
} }
]; ];

View File

@ -0,0 +1,21 @@
<table>
<thead>
<tr>
<th id="first_header" style="text-align:left;"> First Header </th>
<th id="second_header" style="text-align:left;"> Second Header </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"><p>Row 1 Cell 1 </p></td>
<td style="text-align:left;"><p>Row 1 Cell 2 </p></td>
</tr>
<tr>
<td style="text-align:left;"><p>Row 2 Cell 1 </p></td>
<td style="text-align:left;"><p>Row 2 Cell 2 </p></td>
</tr>
</tbody>
</table>

View File

@ -0,0 +1,4 @@
| First Header | Second Header |
| :------------ | :------------ |
| Row 1 Cell 1 | Row 1 Cell 2 |
| Row 2 Cell 1 | Row 2 Cell 2 |