Skip to content

Commit

Permalink
fix(tables): pipe character in code spans no longer breaks table
Browse files Browse the repository at this point in the history
A code span with a pipe character no longer incorrectly breaks the cell table.

Closes #465
  • Loading branch information
tivie committed Nov 23, 2017
1 parent f4f63c5 commit 0c933a0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
4 changes: 3 additions & 1 deletion dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/subParsers/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ showdown.subParser('tables', function (text, options, globals) {
function parseTable (rawTable) {
var i, tableLines = rawTable.split('\n');

// strip wrong first and last column if wrapped tables are used
for (i = 0; i < tableLines.length; ++i) {
// strip wrong first and last column if wrapped tables are used
if (/^ {0,3}\|/.test(tableLines[i])) {
tableLines[i] = tableLines[i].replace(/^ {0,3}\|/, '');
}
if (/\|[ \t]*$/.test(tableLines[i])) {
tableLines[i] = tableLines[i].replace(/\|[ \t]*$/, '');
}
// parse code spans first, but we only support one line code spans
tableLines[i] = showdown.subParser('codeSpans')(tableLines[i], options, globals);
}

var rawHeaders = tableLines[0].split('|').map(function (s) { return s.trim();}),
Expand Down
14 changes: 14 additions & 0 deletions test/features/tables/#465.code-spans-with-pipes-break-table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<table>
<thead>
<tr>
<th>PowerShell command</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>Get-Service</td>
<td><code>Get-Service | Stop-Service -WhatIf</code></td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
|PowerShell command|Example|
|--|--|
|Get-Service|`Get-Service | Stop-Service -WhatIf`|

0 comments on commit 0c933a0

Please sign in to comment.