Pārlūkot izejas kodu

fix(tables): pipe character in code spans no longer breaks table

A code span with a pipe character no longer incorrectly breaks the cell table.

Closes #465
Estevao Soares dos Santos 7 gadi atpakaļ
vecāks
revīzija
0c933a01f9

+ 3 - 1
dist/showdown.js

@@ -4156,14 +4156,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();}),

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/showdown.js.map


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/showdown.min.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/showdown.min.js.map


+ 3 - 1
src/subParsers/tables.js

@@ -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();}),

+ 14 - 0
test/features/tables/#465.code-spans-with-pipes-break-table.html

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

+ 3 - 0
test/features/tables/#465.code-spans-with-pipes-break-table.md

@@ -0,0 +1,3 @@
+|PowerShell command|Example|
+|--|--|
+|Get-Service|`Get-Service | Stop-Service -WhatIf`|

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels