Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add paddedDelimiterRowPipes option #73

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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