Skip to content

Commit

Permalink
fix(tables): pipe char can now be escaped
Browse files Browse the repository at this point in the history
Pipe character is now treated as a special markdown char,
which makes it possible to escape it.

Closes #345
  • Loading branch information
tivie committed Feb 21, 2017
1 parent 5d40c7a commit 1ebc195
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 10 deletions.
10 changes: 7 additions & 3 deletions 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.

6 changes: 3 additions & 3 deletions 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.

2 changes: 1 addition & 1 deletion src/subParsers/encodeBackslashEscapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ showdown.subParser('encodeBackslashEscapes', function (text, options, globals) {
text = globals.converter._dispatch('encodeBackslashEscapes.before', text, options, globals);

text = text.replace(/\\(\\)/g, showdown.helper.escapeCharactersCallback);
text = text.replace(/\\([`*_{}\[\]()>#+.!~=-])/g, showdown.helper.escapeCharactersCallback);
text = text.replace(/\\([`*_{}\[\]()>#+.!~=|-])/g, showdown.helper.escapeCharactersCallback);

text = globals.converter._dispatch('encodeBackslashEscapes.after', text, options, globals);
return text;
Expand Down
2 changes: 1 addition & 1 deletion src/subParsers/escapeSpecialCharsWithinTagAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ showdown.subParser('escapeSpecialCharsWithinTagAttributes', function (text, opti
text = text.replace(regex, function (wholeMatch) {
return wholeMatch
.replace(/(.)<\/?code>(?=.)/g, '$1`')
.replace(/([\\`*_~=])/g, showdown.helper.escapeCharactersCallback);
.replace(/([\\`*_~=|])/g, showdown.helper.escapeCharactersCallback);
});

text = globals.converter._dispatch('escapeSpecialCharsWithinTagAttributes.after', text, options, globals);
Expand Down
4 changes: 4 additions & 0 deletions src/subParsers/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ showdown.subParser('tables', function (text, options, globals) {

text = globals.converter._dispatch('tables.before', text, options, globals);

// find escaped pipe characters
text = text.replace(/\\(\|)/g, showdown.helper.escapeCharactersCallback);

// parse tables
text = text.replace(tableRgx, function (rawTable) {

var i, tableLines = rawTable.split('\n');
Expand Down
30 changes: 30 additions & 0 deletions test/features/tables/#345.escape-pipe-character.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<table>
<thead>
<tr>
<th>Operator</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>&amp;</td>
<td>Logical AND</td>
</tr>
<tr>
<td>&amp;&amp;</td>
<td>Shortcut AND</td>
</tr>
<tr>
<td>|</td>
<td>Logical OR</td>
</tr>
<tr>
<td>||</td>
<td>Shortcut OR</td>
</tr>
<tr>
<td>^</td>
<td>Logical XOR</td>
</tr>
</tbody>
</table>
7 changes: 7 additions & 0 deletions test/features/tables/#345.escape-pipe-character.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
| Operator | Description |
|----------|-------------|
| & | Logical AND |
| && | Shortcut AND |
| \| | Logical OR |
| \|\| | Shortcut OR |
| ^ | Logical XOR |
1 change: 1 addition & 0 deletions test/issues/#345.no-escape-for-the-pipe-character.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>this |</p>
1 change: 1 addition & 0 deletions test/issues/#345.no-escape-for-the-pipe-character.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this \|

0 comments on commit 1ebc195

Please sign in to comment.