diff --git a/src/tableFormatter.ts b/src/tableFormatter.ts index bf7b7ea9..8923dcc9 100644 --- a/src/tableFormatter.ts +++ b/src/tableFormatter.ts @@ -106,8 +106,8 @@ class MarkdownDocumentFormatter implements DocumentFormattingEditProvider { // Alignment of each column let colAlign = [] // Regex to extract cell content. - // Known issue: `\\|` is not correctly parsed as a valid delimiter - let fieldRegExp = new RegExp(/(?:((?:\\\||`.*?`|[^\|])*)\|)/gu); + // GitHub #24 + let fieldRegExp = new RegExp(/((\\\||[^\|])*)\|/gu); // https://www.ling.upenn.edu/courses/Spring_2003/ling538/UnicodeRanges.html let cjkRegex = /[\u3000-\u9fff\uac00-\ud7af\uff01-\uff60]/g; diff --git a/src/test/suite/tableFormatter.test.ts b/src/test/suite/tableFormatter.test.ts index 206c98f9..f9e96472 100644 --- a/src/test/suite/tableFormatter.test.ts +++ b/src/test/suite/tableFormatter.test.ts @@ -53,50 +53,37 @@ suite("Table formatter.", () => { new Selection(0, 0, 0, 0)).then(done, done); }); - test("Contains `|`", done => { + test("Contains '|'", done => { testCommand('editor.action.formatDocument', {}, [ '| a | b |', '| --- | --- |', - '| c `a|b|c` | d `|` |' + '| c `a|b` | d |' ], new Selection(0, 0, 0, 0), [ - '| a | b |', - '| --------- | ----- |', - '| c `a|b|c` | d `|` |' + '| a | b |', + '| ---- | --- |', + '| c `a | b` | d |' ], new Selection(0, 0, 0, 0)).then(done, done); }); - test("Contains ` |`", done => { + // https://github.github.com/gfm/#example-200 + test(String.raw`Contains '\|'`, done => { testCommand('editor.action.formatDocument', {}, [ '| a | b |', '| --- | --- |', - '| c `a |b | c` | d `| ` |' + '| c `a\\|b` | d |', + '| c **a\\|b** | d |' ], new Selection(0, 0, 0, 0), [ - '| a | b |', - '| ------------ | ------ |', - '| c `a |b | c` | d `| ` |' - ], - new Selection(0, 0, 0, 0)).then(done, done); - }); - - test("Contains \\|", done => { - testCommand('editor.action.formatDocument', {}, - [ - '| a | b |', - '| --- | --- |', - '| c \\| b | d \\| |' - ], - new Selection(0, 0, 0, 0), - [ - '| a | b |', - '| ------ | ---- |', - '| c \\| b | d \\| |' + '| a | b |', + '| ---------- | --- |', + '| c `a\\|b` | d |', + '| c **a\\|b** | d |' ], new Selection(0, 0, 0, 0)).then(done, done); }); @@ -214,7 +201,7 @@ suite("Table formatter.", () => { new Selection(0, 0, 0, 0)).then(done, done) }); - test("Contains \\| in last open cell", done => { + test("Contains '\\|' in last open cell", done => { testCommand('editor.action.formatDocument', {}, [ '', // Changing the first expected char somehow crashes the selection logic and the test fails