mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
fix(tables): tables are properly rendered when followed by a single linebreak and a list
Closes #443
This commit is contained in:
parent
a207da1d5f
commit
d88b095f05
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -5,9 +5,9 @@ showdown.subParser('tables', function (text, options, globals) {
|
|||
return text;
|
||||
}
|
||||
|
||||
var tableRgx = /^ {0,3}\|?.+\|.+\n {0,3}\|?[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:[-=]){2,}[\s\S]+?(?:\n\n|¨0)/gm,
|
||||
var tableRgx = /^ {0,3}\|?.+\|.+\n {0,3}\|?[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:[-=]){2,}[\s\S]+?(?:\n\n|<ol|<ul|¨0)/gm,
|
||||
//singeColTblRgx = /^ {0,3}\|.+\|\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n(?: {0,3}\|.+\|\n)+(?:\n\n|¨0)/gm;
|
||||
singeColTblRgx = /^ {0,3}\|.+\|\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|\n( {0,3}\|.+\|\n)*(?:\n|¨0)/gm;
|
||||
singeColTblRgx = /^ {0,3}\|.+\|\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|\n( {0,3}\|.+\|\n)*(?:\n|<ol|<ul|¨0)/gm;
|
||||
|
||||
function parseStyles (sLine) {
|
||||
if (/^:[ \t]*--*$/.test(sLine)) {
|
||||
|
@ -123,11 +123,24 @@ showdown.subParser('tables', function (text, options, globals) {
|
|||
return buildTable(headers, cells);
|
||||
}
|
||||
|
||||
function hackFixTableFollowedByList (rawTable) {
|
||||
var lastChars = rawTable.slice(-3);
|
||||
if (lastChars === '<ol' || lastChars === '<ul') {
|
||||
rawTable = rawTable.slice(0, -3) + '\n\n' + rawTable.slice(-3);
|
||||
}
|
||||
return rawTable;
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('tables.before', text, options, globals);
|
||||
|
||||
// find escaped pipe characters
|
||||
text = text.replace(/\\(\|)/g, showdown.helper.escapeCharactersCallback);
|
||||
|
||||
// hackfix issue #443. Due to lists only having a linebreak before them, we need to manually insert a linebreak to prevent
|
||||
// tables not being parsed when followed by a list
|
||||
text = text.replace(tableRgx, hackFixTableFollowedByList);
|
||||
text = text.replace(singeColTblRgx, hackFixTableFollowedByList);
|
||||
|
||||
// parse multi column tables
|
||||
text = text.replace(tableRgx, parseTable);
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tables</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><strong>col 3 is</strong></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>col 2 is</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>zebra stripes</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<ol>
|
||||
<li>test</li>
|
||||
</ol>
|
|
@ -0,0 +1,7 @@
|
|||
| Tables |
|
||||
| ------------- |
|
||||
| **col 3 is** |
|
||||
| col 2 is |
|
||||
| zebra stripes |
|
||||
|
||||
1. test
|
|
@ -0,0 +1,29 @@
|
|||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tables</th>
|
||||
<th style="text-align:center;">Are</th>
|
||||
<th style="text-align:right;">Cool</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><strong>col 3 is</strong></td>
|
||||
<td style="text-align:center;">right-aligned</td>
|
||||
<td style="text-align:right;">$1600</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>col 2 is</td>
|
||||
<td style="text-align:center;"><em>centered</em></td>
|
||||
<td style="text-align:right;">$12</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>zebra stripes</td>
|
||||
<td style="text-align:center;">are neat</td>
|
||||
<td style="text-align:right;">$1</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<ol>
|
||||
<li>test</li>
|
||||
</ol>
|
|
@ -0,0 +1,7 @@
|
|||
| Tables | Are | Cool |
|
||||
| ------------- |:-------------:| -----:|
|
||||
| **col 3 is** | right-aligned | $1600 |
|
||||
| col 2 is | *centered* | $12 |
|
||||
| zebra stripes | are neat | $1 |
|
||||
|
||||
1. test
|
Loading…
Reference in New Issue
Block a user