Skip to content

Commit 2bfcae9

Browse files
tripodsanahmed-musallamrenovate[bot]
authored
fix: avoid breaking escaped characters (#156)
fixes #154 --------- Co-authored-by: Ahmed <musallam@adobe.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent 08bcaba commit 2bfcae9

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

src/to-markdown.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,13 @@ function blockCodeWithTable(node, parent, context) {
583583
const lines = [];
584584
for (let line of value.split('\n')) {
585585
while (line.length > lineWidth) {
586-
lines.push(`${line.substring(0, lineWidth)}\u0083`);
587-
line = line.substring(lineWidth);
586+
// avoid splitting escaped characters
587+
let len = lineWidth;
588+
if (line[len - 1] === '\\') {
589+
len -= 1;
590+
}
591+
lines.push(`${line.substring(0, len)}\u0083`);
592+
line = line.substring(len);
588593
}
589594
lines.push(line);
590595
}

test/fixtures/gt-wide.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ <h2>Table with wide code block</h2>
1616
</tr>
1717
</tbody>
1818
</table>
19+
<table>
20+
<tbody>
21+
<tr>
22+
<td>Super Code Example</td>
23+
</tr>
24+
<tr>
25+
<td>
26+
<pre><code class="language-js">const test = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever +since the 1500s, when an unknown printer took";
27+
</code></pre>
28+
</td>
29+
</tr>
30+
</tbody>
31+
</table>
1932
<table>
2033
<tbody>
2134
<tr>

test/fixtures/gt-wide.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
| ``` |
2121
+----------------------------------------------------------------------------------------------------------------------------------------------------------+
2222

23+
+---------------------------------------------------------------------------------------------------------------------------------------------------------+
24+
| Super Code Example |
25+
+---------------------------------------------------------------------------------------------------------------------------------------------------------+
26+
| ```js |
27+
| const test = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever ƒ |
28+
| \+since the 1500s, when an unknown printer took"; |
29+
| ``` |
30+
+---------------------------------------------------------------------------------------------------------------------------------------------------------+
31+
2332
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2433
| # Wide Heading: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. |
2534
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

test/gridtable-to-md.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ const CODE_WIDE = `"examples": {
5252
}
5353
}`;
5454

55+
const CODE_WIDE_ESCAPE_CHAR = 'const test = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever +since the 1500s, when an unknown printer took";';
56+
5557
function brk() {
5658
return {
5759
type: 'break',
@@ -575,6 +577,14 @@ describe('gridtable to md', () => {
575577
gtCell(code('json', CODE_WIDE)),
576578
]),
577579
]),
580+
gridTable([
581+
gtRow([
582+
gtCell(text('Super Code Example')),
583+
]),
584+
gtRow([
585+
gtCell(code('js', CODE_WIDE_ESCAPE_CHAR)),
586+
]),
587+
]),
578588
gridTable([
579589
gtRow([
580590
gtCell(heading(1, text('Wide Heading: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'))),

0 commit comments

Comments
 (0)