Skip to content

Commit e2831e5

Browse files
committed
Merge branch 'feature/Alignments' of https://github.com/darkriszty/MarkdownTablePrettify-VSCodeExt into feature/Alignments
2 parents fef49b8 + c0da5ce commit e2831e5

65 files changed

Lines changed: 782 additions & 375 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscodeignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ src/**
88
tsconfig.json
99
vsc-extension-quickstart.md
1010
.travis.yml
11-
demonstration.md
11+
demonstration.md
12+
package-lock.json
13+
gulpfile.js

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88
### Added
9+
- Issue #15: Support alignment options
10+
11+
## 2.0.0 - 2012-02-09
12+
### Added
913
- Issue #12: Full rewrite for refactoring.
1014
- Issue #11: Support escaping of separators with backslash.
1115
- Issue #16: Ignore separators that are in code blocks.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "markdown-table-prettify",
33
"displayName": "Markdown Table Prettifier",
44
"description": "Transforms markdown tables to be more readable.",
5-
"version": "1.1.1",
5+
"version": "2.0.0",
66
"publisher": "darkriszty",
77
"repository": {
88
"type": "git",

src/extension/extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { RowViewModelFactory } from '../viewModelFactories/rowViewModelFactory';
1313
import { TrimmerTransformer } from '../modelFactory/transformers/trimmerTransformer';
1414
import { BorderTransformer } from '../modelFactory/transformers/borderTransformer';
1515
import { SelectionInterpreter } from '../modelFactory/selectionInterpreter';
16-
import { SeparatorPadCalculator } from '../padCalculation/separatorPadCalculator';
1716
import { PadCalculatorSelector } from '../padCalculation/padCalculatorSelector';
17+
import { AlignmentMarkerStrategy } from '../viewModelFactories/alignmentMarking';
1818

1919
// This method is called when the extension is activated.
2020
// The extension is activated the very first time the command is executed.
@@ -31,8 +31,8 @@ export function activate(context: vscode.ExtensionContext): void {
3131
new TableValidator(new SelectionInterpreter()),
3232
new TableViewModelFactory(
3333
new RowViewModelFactory(
34-
new ContentPadCalculator(new PadCalculatorSelector(), " "),
35-
new SeparatorPadCalculator(new PadCalculatorSelector(), "-")
34+
new ContentPadCalculator(new PadCalculatorSelector(), " "),
35+
new AlignmentMarkerStrategy(":")
3636
)
3737
),
3838
new TableStringWriter(),

src/padCalculation/basePadCalculator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Table } from "../models/table";
22
import { Cell } from "../models/cell";
33

44
export abstract class BasePadCalculator {
5-
public abstract getLeftPadding(paddingChar: string, table: Table, cell: Cell): string;
5+
public abstract getLeftPadding(paddingChar: string, table: Table, row: number, column: number): string;
66
public abstract getRightPadding(paddingChar: string, table: Table, row: number, column: number): string;
77

88
protected baseGetRightPadding(paddingChar: string, table: Table, row: number, column: number): string {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Table } from "../../models/table";
2+
import { Cell } from "../../models/cell";
3+
import { BasePadCalculator } from "../basePadCalculator";
4+
5+
export abstract class CenterPadCalculator extends BasePadCalculator {
6+
public getLeftPadding(paddingChar: string, table: Table, row: number, column: number): string {
7+
return paddingChar.repeat(Math.floor(this.totalPadCount(table, column, row)));
8+
}
9+
10+
public getRightPadding(paddingChar: string, table: Table, row: number, column: number): string {
11+
return paddingChar.repeat(Math.ceil(this.totalPadCount(table, column, row)));
12+
}
13+
14+
protected totalPadCount(table: Table, column: number, row: number): number {
15+
const longestColumnLength = table.getLongestColumnLengths()[column];
16+
let padCount = longestColumnLength > 0
17+
? longestColumnLength - table.rows[row][column].getLength()
18+
: 1;
19+
padCount += this.extraPadCount(table);
20+
return padCount / 2;
21+
}
22+
23+
protected extraPadCount(table: Table): number {
24+
return 2;
25+
}
26+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Table } from "../../models/table";
2+
import { CenterPadCalculator } from "./centerPadCalculator";
3+
4+
export class FirstColumnPadCalculator extends CenterPadCalculator {
5+
protected extraPadCount(table: Table): number {
6+
return table.hasLeftBorder ? 2 : 1;
7+
}
8+
}

src/padCalculation/center/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./firstColumnPadCalculator"
2+
export * from "./middleColumnPadCalculator"
3+
export * from "./lastColumnPadCalculator"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Table } from "../../models/table";
2+
import { CenterPadCalculator } from "./centerPadCalculator";
3+
4+
export class LastColumnPadCalculator extends CenterPadCalculator {
5+
public getRightPadding(paddingChar: string, table: Table, row: number, column: number): string {
6+
if (!table.hasRightBorder) return "";
7+
return super.getRightPadding(paddingChar, table, row, column);
8+
}
9+
}

0 commit comments

Comments
 (0)