Skip to content

Commit

Permalink
💥 #24 [breaking change] pipe inside table cell
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhang committed Dec 13, 2020
1 parent 736d5d7 commit c87fb12
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/tableFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
41 changes: 14 additions & 27 deletions src/test/suite/tableFormatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c87fb12

Please sign in to comment.