Skip to content

Commit

Permalink
Add paddedDelimiterRowPipes option
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng committed Jan 1, 2025
1 parent 58b7578 commit 5f88598
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions src/markdownTableDataHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export function getColumnMaxWidths(tableData: MarkdownTableData): number[] {
export function toFormatTableStr(tableData: MarkdownTableData): string {
const alignData = <boolean>workspace.getConfiguration('markdowntable').get('alignData');
const alignHeader = <boolean>workspace.getConfiguration('markdowntable').get('alignColumnHeader');
const paddedDelimiterRowPipes = <boolean>workspace.getConfiguration('markdowntable').get('paddedDelimiterRowPipes');

// 各列の最大文字数を調べる
const maxWidths = getColumnMaxWidths(tableData);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5f88598

Please sign in to comment.