瀏覽代碼

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
Estevao Soares dos Santos 8 年之前
父節點
當前提交
1ebc1959dd

+ 7 - 3
dist/showdown.js

@@ -1,4 +1,4 @@
-;/*! showdown 14-02-2017 */
+;/*! showdown 21-02-2017 */
 (function(){
 /**
  * Created by Tivie on 13-07-2015.
@@ -1667,7 +1667,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;
@@ -1712,7 +1712,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);
@@ -2663,6 +2663,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');

文件差異過大導致無法顯示
+ 0 - 0
dist/showdown.js.map


文件差異過大導致無法顯示
+ 1 - 1
dist/showdown.min.js


文件差異過大導致無法顯示
+ 0 - 0
dist/showdown.min.js.map


+ 1 - 1
src/subParsers/encodeBackslashEscapes.js

@@ -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;

+ 1 - 1
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);

+ 4 - 0
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');

+ 30 - 0
test/features/tables/#345.escape-pipe-character.html

@@ -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 - 0
test/features/tables/#345.escape-pipe-character.md

@@ -0,0 +1,7 @@
+| Operator | Description |
+|----------|-------------|
+| & | Logical AND |
+| && | Shortcut AND |
+| \| | Logical OR |
+| \|\| | Shortcut OR |
+| ^ | Logical XOR |

+ 1 - 0
test/issues/#345.no-escape-for-the-pipe-character.html

@@ -0,0 +1 @@
+<p>this |</p>

+ 1 - 0
test/issues/#345.no-escape-for-the-pipe-character.md

@@ -0,0 +1 @@
+this \|

部分文件因文件數量過多而無法顯示