From 5f885989ca6514497e9074cee51897972faba7c3 Mon Sep 17 00:00:00 2001 From: jimtng <2554958+jimtng@users.noreply.github.com> Date: Wed, 1 Jan 2025 16:15:56 +1000 Subject: [PATCH] Add paddedDelimiterRowPipes option Signed-off-by: Jimmy Tanagra --- README.md | 33 +++++++++++++++++---------------- package-lock.json | 4 ++-- package.json | 5 +++++ src/markdownTableDataHelper.ts | 13 +++++++++++-- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 01131bb..6dee716 100644 --- a/README.md +++ b/README.md @@ -91,22 +91,23 @@ Key binding to `Shift`+`Tab`. ## 3. Extension Configurations -| Configuration ID | Description | Type | Default | -| :--------------------------------- | :--------------------------------------------------------- | :------ | :------ | -| markdowntable.alignColumnHeader | Align column header in the table when formatting | boolean | true | -| markdowntable.alignData | Align data in the table when formatting | boolean | true | -| markdowntable.ignoreCodeblock | Ignore tables in code block | boolean | true | -| markdowntable.showMenu.format | Show command in context menu, "Format all tables" | boolean | true | -| markdowntable.showMenu.tsvToTable | Show command in context menu, "Convert TSV to table" | boolean | true | -| markdowntable.showMenu.csvToTable | Show command in context menu, "Convert CSV to table" | boolean | false | -| markdowntable.showMenu.insertRight | Show command in context menu, "Insert column to the right" | boolean | true | -| markdowntable.showMenu.insertLeft | Show command in context menu, "Insert column to the left" | boolean | true | -| markdowntable.showMenu.alignLeft | Show command in context menu, "Align to Left" | boolean | true | -| markdowntable.showMenu.alignCenter | Show command in context menu, "Align to Center" | boolean | true | -| markdowntable.showMenu.alignRight | Show command in context menu, "Align to Right" | boolean | true | -| markdowntable.showMenu.moveLeft | Show command in context menu, "Move to Left" | boolean | true | -| markdowntable.showMenu.moveRight | Show command in context menu, "Move to Right" | boolean | true | -| markdowntable.formatOnSave | Format all tables on save | boolean | false | +| Configuration ID | Description | Type | Default | +| :------------------------------------ | :--------------------------------------------------------- | :------ | :------ | +| markdowntable.alignColumnHeader | Align column header in the table when formatting | boolean | true | +| markdowntable.alignData | Align data in the table when formatting | boolean | true | +| markdowntable.ignoreCodeblock | Ignore tables in code block | boolean | true | +| markdowntable.paddedDelimiterRowPipes | Add spaces around delimiter row pipes | boolean | true | +| markdowntable.showMenu.format | Show command in context menu, "Format all tables" | boolean | true | +| markdowntable.showMenu.tsvToTable | Show command in context menu, "Convert TSV to table" | boolean | true | +| markdowntable.showMenu.csvToTable | Show command in context menu, "Convert CSV to table" | boolean | false | +| markdowntable.showMenu.insertRight | Show command in context menu, "Insert column to the right" | boolean | true | +| markdowntable.showMenu.insertLeft | Show command in context menu, "Insert column to the left" | boolean | true | +| markdowntable.showMenu.alignLeft | Show command in context menu, "Align to Left" | boolean | true | +| markdowntable.showMenu.alignCenter | Show command in context menu, "Align to Center" | boolean | true | +| markdowntable.showMenu.alignRight | Show command in context menu, "Align to Right" | boolean | true | +| markdowntable.showMenu.moveLeft | Show command in context menu, "Move to Left" | boolean | true | +| markdowntable.showMenu.moveRight | Show command in context menu, "Move to Right" | boolean | true | +| markdowntable.formatOnSave | Format all tables on save | boolean | false | ## 4. Tips diff --git a/package-lock.json b/package-lock.json index aff176e..9ac5e5f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "markdowntable", - "version": "0.11.0", + "version": "0.12.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "markdowntable", - "version": "0.11.0", + "version": "0.12.0", "devDependencies": { "@types/glob": "^8.1.0", "@types/mocha": "^10.0.2", diff --git a/package.json b/package.json index 64fa83e..0da31d3 100644 --- a/package.json +++ b/package.json @@ -164,6 +164,11 @@ "default": true, "description": "Ignore tables in codeblock" }, + "markdowntable.paddedDelimiterRowPipes": { + "type": "boolean", + "default": true, + "description": "Add spaces around delimiter row pipes." + }, "markdowntable.showMenu.format": { "type": "boolean", "default": true, diff --git a/src/markdownTableDataHelper.ts b/src/markdownTableDataHelper.ts index 236cc37..05e50ec 100644 --- a/src/markdownTableDataHelper.ts +++ b/src/markdownTableDataHelper.ts @@ -205,6 +205,7 @@ export function getColumnMaxWidths(tableData: MarkdownTableData): number[] { export function toFormatTableStr(tableData: MarkdownTableData): string { const alignData = workspace.getConfiguration('markdowntable').get('alignData'); const alignHeader = workspace.getConfiguration('markdowntable').get('alignColumnHeader'); + const paddedDelimiterRowPipes = workspace.getConfiguration('markdowntable').get('paddedDelimiterRowPipes'); // 各列の最大文字数を調べる const maxWidths = getColumnMaxWidths(tableData); @@ -325,12 +326,20 @@ export function toFormatTableStr(tableData: MarkdownTableData): string { // 2行目を成形する for (let i = 0; i < columnNum; i++) { const [front, end] = tableData.aligns[i]; - tableData.alignTexts[i] = ' ' + front; + if (paddedDelimiterRowPipes) { + tableData.alignTexts[i] = ' ' + front; + } else { + tableData.alignTexts[i] = front + '-'; + } // 余白を-で埋める for (let n = 1; n < maxWidths[i] - 1; n++) { tableData.alignTexts[i] += '-'; } - tableData.alignTexts[i] += end + ' '; + if (paddedDelimiterRowPipes) { + tableData.alignTexts[i] += end + ' '; + } else { + tableData.alignTexts[i] += '-' + end; + } } let tablemark = ''; tablemark += tableData.indent;