mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
Added fix to prevent table rendering to be broken by alignment character ":".
This commit is contained in:
parent
bd242722bb
commit
3dbc6ffcfb
|
@ -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
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
21
test/extensions/table/basic-alignment.html
Normal file
21
test/extensions/table/basic-alignment.html
Normal 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>
|
4
test/extensions/table/basic-alignment.md
Normal file
4
test/extensions/table/basic-alignment.md
Normal 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 |
|
Loading…
Reference in New Issue
Block a user