Skip to content

Commit

Permalink
Merge pull request #1239 from tomtheisen/escapedpipes
Browse files Browse the repository at this point in the history
Escapedpipes
  • Loading branch information
joshbruce authored Apr 25, 2018
2 parents ecdef45 + e4973ed commit c5cc037
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
21 changes: 15 additions & 6 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ Lexer.prototype.token = function(src, top) {

item = {
type: 'table',
header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
cells: cap[3].replace(/\n$/, '').split('\n')
};
Expand All @@ -267,7 +267,7 @@ Lexer.prototype.token = function(src, top) {
}

for (i = 0; i < item.cells.length; i++) {
item.cells[i] = item.cells[i].split(/ *\| */);
item.cells[i] = splitCells(item.cells[i]);
}

this.tokens.push(item);
Expand Down Expand Up @@ -416,7 +416,7 @@ Lexer.prototype.token = function(src, top) {

item = {
type: 'table',
header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')),
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
};
Expand All @@ -434,9 +434,8 @@ Lexer.prototype.token = function(src, top) {
}

for (i = 0; i < item.cells.length; i++) {
item.cells[i] = item.cells[i]
.replace(/^ *\| *| *\| *$/g, '')
.split(/ *\| */);
item.cells[i] = splitCells(
item.cells[i].replace(/^ *\| *| *\| *$/g, ''));
}

this.tokens.push(item);
Expand Down Expand Up @@ -1311,6 +1310,16 @@ function merge(obj) {
return obj;
}

function splitCells(tableRow) {
var cells = tableRow.replace(/([^\\])\|/g, '$1 |').split(/ +\| */),
i = 0;

for (; i < cells.length; i++) {
cells[i] = cells[i].replace(/\\\|/g, '|');
}
return cells;
}

/**
* Marked
*/
Expand Down
3 changes: 1 addition & 2 deletions test/specs/gfm/gfm-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ var messenger = new Messenger();
describe('GFM 0.28 Tables', function() {
var section = 'Tables';

// TODO: Verify exmaple 193 is valid and passing
var shouldPassButFails = [192, 193, 195, 196, 197];
var shouldPassButFails = [192, 195, 196, 197];

var willNotBeAttemptedByCoreTeam = [];

Expand Down

0 comments on commit c5cc037

Please sign in to comment.