From 1ebc1959dd8b357c010646c2dd98a2ce337717c6 Mon Sep 17 00:00:00 2001 From: Estevao Soares dos Santos Date: Tue, 21 Feb 2017 14:13:12 +0000 Subject: [PATCH] fix(tables): pipe char can now be escaped Pipe character is now treated as a special markdown char, which makes it possible to escape it. Closes #345 --- dist/showdown.js | Bin 83619 -> 83750 bytes dist/showdown.js.map | Bin 243211 -> 243544 bytes dist/showdown.min.js | Bin 34953 -> 35012 bytes dist/showdown.min.js.map | Bin 37811 -> 37857 bytes src/subParsers/encodeBackslashEscapes.js | 2 +- .../escapeSpecialCharsWithinTagAttributes.js | 2 +- src/subParsers/tables.js | 4 +++ .../tables/#345.escape-pipe-character.html | 30 ++++++++++++++++++ .../tables/#345.escape-pipe-character.md | 7 ++++ ...#345.no-escape-for-the-pipe-character.html | 1 + .../#345.no-escape-for-the-pipe-character.md | 1 + 11 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 test/features/tables/#345.escape-pipe-character.html create mode 100644 test/features/tables/#345.escape-pipe-character.md create mode 100644 test/issues/#345.no-escape-for-the-pipe-character.html create mode 100644 test/issues/#345.no-escape-for-the-pipe-character.md diff --git a/dist/showdown.js b/dist/showdown.js index 94349cba7a8a6d26a29cb2ec1677c74a127ddbba..dcdf75c4015e0ddbe045293f38a940185f37016e 100644 GIT binary patch delta 117 zcmZ47%et(ORlr(bOHrXXBfmT)zdTRD$Z(^;gRP7;n?Gz_&Bj$@v8Xsz Tp(HUWClw?szWtXq<4P_7T0<HQ1rR$gDj^_qXm599Z+C7WF*LCd;I*^ywW|h`F1azY&b%6blTW_| NlYX@iw|zVTsS04~7SaF! diff --git a/dist/showdown.js.map b/dist/showdown.js.map index fe9eac15da509fb8b1a77b14b48d003cc5bebe19..a915d0be32ca7679f377bf9170b6d32d35c1f09e 100644 GIT binary patch delta 323 zcmeBv!*}ByU&9v0eL<5OdKIP?FiJA%yG_5S$z(g-Pn(H-yKOMz6|Tv1(zqsX(Bqo^ zL7Y)!y1)TOen!LTjf)wjr=N>sGTJ^Zj`7s{>AmcXT+?+s8M!7K%;B0op%lpT?qoEc z9u&lAIo-yPNpw2jX`oobK1LQ+Yez@ttmzw_7_}x}=whAzK?kVIL4$Sjfh;(^eS;rU zC@*t?r^n=p+EUXWXfTOPcKFCQ&6tU6azhW>RDGb91)I30uQvlSChP>-n8?UEdBPNy z?VT}9yoVWUroU5SPMm&Ej#+R!hXQjM8&KrE60_0v4Qk9uEpqz$3Tc^nDGI5@$%zH2 zDGCLd1*rifksSB&GZjS%%;3R9R-O+#i&ONn&QF6Lc5ToMs51LGJ)BUuW*tgpTGhX4E?32wk zc|sW1^bg{UBGUy9F!D22O>bPxC_Vj-CX>p9F-cPrQWz?AdL5GoRvV#We^~uuLAQ{HWnD)V0*bbb3)7XoAS&e+l$vQ HKji`dGm%XJ diff --git a/dist/showdown.min.js b/dist/showdown.min.js index 4e1842b6638b419b222119c7d1114d1725583634..e4073afa07416768a31a84a2a1a4a9f13c89f541 100644 GIT binary patch delta 68 zcmV-K0K5N*kpje#0uL`LAs};TZ+B#GcWxjuF|iL&O9Ff?lQB*wleyk*RYc6TiNeqC#;-etAlMd7gry$wvMF@68F`mzX9edaG}a@^duZe5LsV3jk>M B5ZwR( diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index 946a88b6797cba9da3f1fa1c6ed1de2f046c803d..6c893618254a404fac1b4e66609174629bc80183 100644 GIT binary patch delta 128 zcmdnIoay0mrVY}eG8Rsbj@nLXIP=>Px# delta 117 zcmaF3oN4oNrVY}elkYpTiKXedIyweB>-al5`lsp`I61oJxaPY|R?Lvx91!}RQ99Mp zG2IDOk%^O|ySXz|QAzj)Q|@w)G@t<`u8u{%lP|_fPQF#+.!~=-])/g, showdown.helper.escapeCharactersCallback); + text = text.replace(/\\([`*_{}\[\]()>#+.!~=|-])/g, showdown.helper.escapeCharactersCallback); text = globals.converter._dispatch('encodeBackslashEscapes.after', text, options, globals); return text; diff --git a/src/subParsers/escapeSpecialCharsWithinTagAttributes.js b/src/subParsers/escapeSpecialCharsWithinTagAttributes.js index 4a0e929..27fc3ce 100644 --- a/src/subParsers/escapeSpecialCharsWithinTagAttributes.js +++ b/src/subParsers/escapeSpecialCharsWithinTagAttributes.js @@ -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); diff --git a/src/subParsers/tables.js b/src/subParsers/tables.js index 79498eb..dcd74c9 100644 --- a/src/subParsers/tables.js +++ b/src/subParsers/tables.js @@ -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'); diff --git a/test/features/tables/#345.escape-pipe-character.html b/test/features/tables/#345.escape-pipe-character.html new file mode 100644 index 0000000..059ef88 --- /dev/null +++ b/test/features/tables/#345.escape-pipe-character.html @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OperatorDescription
&Logical AND
&&Shortcut AND
|Logical OR
||Shortcut OR
^Logical XOR
diff --git a/test/features/tables/#345.escape-pipe-character.md b/test/features/tables/#345.escape-pipe-character.md new file mode 100644 index 0000000..690b649 --- /dev/null +++ b/test/features/tables/#345.escape-pipe-character.md @@ -0,0 +1,7 @@ +| Operator | Description | +|----------|-------------| +| & | Logical AND | +| && | Shortcut AND | +| \| | Logical OR | +| \|\| | Shortcut OR | +| ^ | Logical XOR | diff --git a/test/issues/#345.no-escape-for-the-pipe-character.html b/test/issues/#345.no-escape-for-the-pipe-character.html new file mode 100644 index 0000000..9c79cde --- /dev/null +++ b/test/issues/#345.no-escape-for-the-pipe-character.html @@ -0,0 +1 @@ +

this |

diff --git a/test/issues/#345.no-escape-for-the-pipe-character.md b/test/issues/#345.no-escape-for-the-pipe-character.md new file mode 100644 index 0000000..26055b3 --- /dev/null +++ b/test/issues/#345.no-escape-for-the-pipe-character.md @@ -0,0 +1 @@ +this \|