-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix table cells #1262
Fix table cells #1262
Conversation
return ' |'; | ||
} | ||
}), | ||
cells = row.split(/ \|/), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally had a very complex replace regex but I couldn't get it to not be vulnerable to catastrophic backtracking, but this works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer code to complex regexes anyway :-)
test/specs/marked/marked.json
Outdated
@@ -2,7 +2,31 @@ | |||
{ | |||
"section": "Code spans", | |||
"markdown": "`someone@example.com`", | |||
"html": "<p><code>someone@exmaple.com</code></p>\n", | |||
"html": "<p><code>someone@exmaple.com</code></p>", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, and looks like a holdover, but "exmaple" -> "example" ?
test/specs/marked/marked.json
Outdated
"example": 1 | ||
}, | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice set of tests. Could you add one or two really simple ones, e.g.
|1|
|1\||
|1\\1|
Starting simple makes the later ones easier to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still no example with a singly-escaped pipe? \|
lib/marked.js
Outdated
@@ -1340,7 +1340,20 @@ function merge(obj) { | |||
} | |||
|
|||
function splitCells(tableRow, count) { | |||
var cells = tableRow.replace(/([^\\])\|/g, '$1 |').split(/ +\| */), | |||
var row = tableRow.replace(/\|/g, function (match, offset, str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment above this line/function explaining its purpose? (It looks like the goal is to ensure that every cell-delimiting pipe has a space before it, so that you can split cells on ' |'
).
lib/marked.js
Outdated
@@ -1350,7 +1363,7 @@ function splitCells(tableRow, count) { | |||
} | |||
|
|||
for (; i < cells.length; i++) { | |||
cells[i] = cells[i].replace(/\\\|/g, '|'); | |||
cells[i] = cells[i].trim().replace(/\\\|/g, '|'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth noting in a comment that leading or trailing whitespace is ignored per the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, a few nits here and there.
|
|
|
|
Fix table cells
Marked version: master
Markdown flavor: Markdown.pl|CommonMark|GitHub Flavored Markdown|n/a
Description
|
fixes #1290
Contributor
Committer
In most cases, this should be a different person than the contributor.