Skip to content

Commit

Permalink
Fix bug #19 where the extension would fail to format a table with col…
Browse files Browse the repository at this point in the history
…umns header and lines with 1 character
  • Loading branch information
fcrespo82 committed Jan 24, 2020
1 parent 18e33c0 commit a063408
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.0.3

* [FIX] Fix bug #19 where the extension would fail to format a table with columns header and lines with 1 character

## 2.0.2

* [CHANGED] A lot of internal fixes and improvements

## 2.0.1

* [FIX] Various bugs
Expand Down
4 changes: 3 additions & 1 deletion src/MarkdownTableUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export let swidth = (str: string) => {
};

export let padding = (len: number, str: string = ' ') => {
return str.repeat(len);
var r = len >= 0 ? str.repeat(len) : "";
// var r = str.repeat(len);
return r;
};

export let columnSizes = (header: string[], body: string[][]) => {
Expand Down
2 changes: 1 addition & 1 deletion src/formatter/MarkdownTableFormatterProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class MarkdownTableFormatterProvider implements vscode.DocumentFormatting
line = front + padding(table.columnSizes[i] + (settings.spacePadding * 2) - 2, '-') + back;
break;
case MarkdownTableFormatterDelimiterRowPadding.FollowSpacePadding:
line = `${spacePadding}${front}${padding(table.columnSizes[i] - 2, '-')}${back}${spacePadding}`;
line = `${spacePadding}${front}${padding(table.columnSizes[i] - 2, '-')}${table.columnSizes[i]===1?'':back}${spacePadding}`;
break;
case MarkdownTableFormatterDelimiterRowPadding.SingleApaceAlways:
line = ` ${front}${padding(table.columnSizes[i] + (settings.spacePadding * 2) - 4, '-')}${back} `;
Expand Down

0 comments on commit a063408

Please # to comment.