Skip to content

Commit 2e71f15

Browse files
committed
Ignore separators in code blocks
1 parent e0e9670 commit 2e71f15

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/modelFactory/selectionInterpreter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class SelectionInterpreter {
1616
index = -1,
1717
previousSplitIndex = -1;
1818
while ((index = line.indexOf("|", index + 1)) > -1) {
19-
if (line[index - 1] != "\\") {
19+
if (line[index - 1] != "\\" && !this.codeBlockOpenTill(line.substr(0, index))) {
2020
result.push(line.substring(previousSplitIndex + 1, index));
2121
previousSplitIndex = index;
2222
}
@@ -25,4 +25,8 @@ export class SelectionInterpreter {
2525

2626
return result;
2727
}
28+
29+
private codeBlockOpenTill(text: string): boolean {
30+
return (text.match(/`/g) || []).length % 2 != 0;
31+
}
2832
}

test/systemTests/resources/escapeCodeBlock-input.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Type | Range| Size
22
-|-|-
3-
sbyte | -128 `|`|to|`|` 127| Signed 8-bit integer
3+
sbyte | -128 `|to|` 127| Signed 8-bit integer
44
byte| 0 `|to|` 255| Unsigned 8-bit integer
55
char| U+0000 `|to|` U+ffff| Unicode 16-bit character
66
short| -32,768 `|to|` 32,767| Signed 16-bit integer

test/unitTests/modelFactory/selectionInterpreter.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ suite("SelectionInterpreter tests", () => {
7575
assert.equal(rows[1][1], "v2");
7676
});
7777

78-
test("allRows() doesn't consider separator that's in a code block 1", () => {
78+
test("allRows() doesn't consider separator that's in a `code block` #1", () => {
7979
const text = "`h1|h2|h3`";
8080
const sut = createSut();
8181

@@ -86,7 +86,7 @@ suite("SelectionInterpreter tests", () => {
8686
assert.equal(rows[0][0], "`h1|h2|h3`");
8787
});
8888

89-
test("allRows() doesn't consider separator that's in a code block 2", () => {
89+
test("allRows() doesn't consider separator that's in a `code block` #2", () => {
9090
const text = "h1|h2`|still|h2`|h3";
9191
const sut = createSut();
9292

@@ -99,15 +99,15 @@ suite("SelectionInterpreter tests", () => {
9999
assert.equal(rows[0][2], "h3");
100100
});
101101

102-
test("allRows() doesn't consider separator that's in a code block 3", () => {
102+
test("allRows() doesn't consider separator that's in a `code block` #3", () => {
103103
const text = "`h1|h1`|h2|h3`|h3`";
104104
const sut = createSut();
105105

106106
const rows = sut.allRows(text);
107107

108108
assert.equal(rows.length, 1);
109109
assert.equal(rows[0].length, 3);
110-
assert.equal(rows[0][0], "h1|h1");
110+
assert.equal(rows[0][0], "`h1|h1`");
111111
assert.equal(rows[0][1], "h2");
112112
assert.equal(rows[0][2], "h3`|h3`");
113113
});

0 commit comments

Comments
 (0)