From a063408d19b4426b9d39d8b48582d51cb7b76c78 Mon Sep 17 00:00:00 2001 From: Fernando Crespo Date: Fri, 24 Jan 2020 18:29:00 -0300 Subject: [PATCH] Fix bug #19 where the extension would fail to format a table with columns header and lines with 1 character --- CHANGELOG.md | 8 ++++++++ src/MarkdownTableUtils.ts | 4 +++- src/formatter/MarkdownTableFormatterProvider.ts | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b45f6e5..30a5e7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/MarkdownTableUtils.ts b/src/MarkdownTableUtils.ts index 504e538..8ec8182 100644 --- a/src/MarkdownTableUtils.ts +++ b/src/MarkdownTableUtils.ts @@ -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[][]) => { diff --git a/src/formatter/MarkdownTableFormatterProvider.ts b/src/formatter/MarkdownTableFormatterProvider.ts index 86f7b69..d82e920 100644 --- a/src/formatter/MarkdownTableFormatterProvider.ts +++ b/src/formatter/MarkdownTableFormatterProvider.ts @@ -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} `;