mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
fix(tables): raw html inside code tags in tables no longer breaks tables
Under certains conditions, raw html inside code tags in tables would break table parsing. This commit fixes that. Closes #471
This commit is contained in:
parent
32541e6894
commit
4ef4c5e674
27
dist/showdown.js
vendored
27
dist/showdown.js
vendored
@ -1,4 +1,4 @@
|
||||
;/*! showdown v 1.8.3 - 28-11-2017 */
|
||||
;/*! showdown v 1.8.3 - 05-12-2017 */
|
||||
(function(){
|
||||
/**
|
||||
* Created by Tivie on 13-07-2015.
|
||||
@ -3812,7 +3812,7 @@ showdown.subParser('lists', function (text, options, globals) {
|
||||
style = styleStartNumber(list, listType);
|
||||
if (pos !== -1) {
|
||||
// slice
|
||||
result += '\n<' + listType + style + '>\n' + processListItems(txt.slice(0, pos), !!trimTrailing) + '</' + listType + '>\n';
|
||||
result += '\n\n<' + listType + style + '>\n' + processListItems(txt.slice(0, pos), !!trimTrailing) + '</' + listType + '>\n';
|
||||
|
||||
// invert counterType and listType
|
||||
listType = (listType === 'ul') ? 'ol' : 'ul';
|
||||
@ -3821,12 +3821,12 @@ showdown.subParser('lists', function (text, options, globals) {
|
||||
//recurse
|
||||
parseCL(txt.slice(pos));
|
||||
} else {
|
||||
result += '\n<' + listType + style + '>\n' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n';
|
||||
result += '\n\n<' + listType + style + '>\n' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n';
|
||||
}
|
||||
})(list);
|
||||
} else {
|
||||
var style = styleStartNumber(list, listType);
|
||||
result = '\n<' + listType + style + '>\n' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n';
|
||||
result = '\n\n<' + listType + style + '>\n' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n';
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -4100,9 +4100,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|<ol|<ul|¨0)/gm,
|
||||
var tableRgx = /^ {0,3}\|?.+\|.+\n {0,3}\|?[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:[-=]){2,}[\s\S]+?(?:\n\n|¨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}\|.+\|[ \t]*\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n( {0,3}\|.+\|[ \t]*\n)*(?:\n|<ol|<ul|¨0)/gm;
|
||||
singeColTblRgx = /^ {0,3}\|.+\|[ \t]*\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n( {0,3}\|.+\|[ \t]*\n)*(?:\n|¨0)/gm;
|
||||
|
||||
function parseStyles (sLine) {
|
||||
if (/^:[ \t]*--*$/.test(sLine)) {
|
||||
@ -4119,7 +4119,7 @@ showdown.subParser('tables', function (text, options, globals) {
|
||||
function parseHeaders (header, style) {
|
||||
var id = '';
|
||||
header = header.trim();
|
||||
// support both tablesHeaderId and tableHeaderId due to error in documention so we don't break backwards compatibility
|
||||
// support both tablesHeaderId and tableHeaderId due to error in documentation so we don't break backwards compatibility
|
||||
if (options.tablesHeaderId || options.tableHeaderId) {
|
||||
id = ' id="' + header.replace(/ /g, '_').toLowerCase() + '"';
|
||||
}
|
||||
@ -4220,24 +4220,11 @@ 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);
|
||||
|
||||
|
2
dist/showdown.js.map
vendored
2
dist/showdown.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/showdown.min.js
vendored
4
dist/showdown.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/showdown.min.js.map
vendored
2
dist/showdown.min.js.map
vendored
File diff suppressed because one or more lines are too long
@ -154,7 +154,7 @@ showdown.subParser('lists', function (text, options, globals) {
|
||||
style = styleStartNumber(list, listType);
|
||||
if (pos !== -1) {
|
||||
// slice
|
||||
result += '\n<' + listType + style + '>\n' + processListItems(txt.slice(0, pos), !!trimTrailing) + '</' + listType + '>\n';
|
||||
result += '\n\n<' + listType + style + '>\n' + processListItems(txt.slice(0, pos), !!trimTrailing) + '</' + listType + '>\n';
|
||||
|
||||
// invert counterType and listType
|
||||
listType = (listType === 'ul') ? 'ol' : 'ul';
|
||||
@ -163,12 +163,12 @@ showdown.subParser('lists', function (text, options, globals) {
|
||||
//recurse
|
||||
parseCL(txt.slice(pos));
|
||||
} else {
|
||||
result += '\n<' + listType + style + '>\n' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n';
|
||||
result += '\n\n<' + listType + style + '>\n' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n';
|
||||
}
|
||||
})(list);
|
||||
} else {
|
||||
var style = styleStartNumber(list, listType);
|
||||
result = '\n<' + listType + style + '>\n' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n';
|
||||
result = '\n\n<' + listType + style + '>\n' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n';
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -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|<ol|<ul|¨0)/gm,
|
||||
var tableRgx = /^ {0,3}\|?.+\|.+\n {0,3}\|?[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:[-=]){2,}[\s\S]+?(?:\n\n|¨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}\|.+\|[ \t]*\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n( {0,3}\|.+\|[ \t]*\n)*(?:\n|<ol|<ul|¨0)/gm;
|
||||
singeColTblRgx = /^ {0,3}\|.+\|[ \t]*\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n( {0,3}\|.+\|[ \t]*\n)*(?:\n|¨0)/gm;
|
||||
|
||||
function parseStyles (sLine) {
|
||||
if (/^:[ \t]*--*$/.test(sLine)) {
|
||||
@ -24,7 +24,7 @@ showdown.subParser('tables', function (text, options, globals) {
|
||||
function parseHeaders (header, style) {
|
||||
var id = '';
|
||||
header = header.trim();
|
||||
// support both tablesHeaderId and tableHeaderId due to error in documention so we don't break backwards compatibility
|
||||
// support both tablesHeaderId and tableHeaderId due to error in documentation so we don't break backwards compatibility
|
||||
if (options.tablesHeaderId || options.tableHeaderId) {
|
||||
id = ' id="' + header.replace(/ /g, '_').toLowerCase() + '"';
|
||||
}
|
||||
@ -125,24 +125,11 @@ 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,14 @@
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="text-align:right;">h1</th>
|
||||
<th style="text-align:left;">h2</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="text-align:right;">asdf</td>
|
||||
<td style="text-align:left;">one <code>two <ol> three</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
@ -0,0 +1,3 @@
|
||||
| h1 | h2 |
|
||||
|--------:|:---------------------|
|
||||
| asdf | one `two <ol> three` |
|
Loading…
x
Reference in New Issue
Block a user