markdown-it-adv-table 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -21
- package/RELEASE.md +37 -0
- package/lib/table-builder.js +5 -4
- package/lib/table.d.ts +5 -2
- package/lib/table.js +21 -13
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -61,9 +61,7 @@ const html = md.render("text...");
|
|
|
61
61
|
</tr>
|
|
62
62
|
</table>
|
|
63
63
|
|
|
64
|
-
##
|
|
65
|
-
|
|
66
|
-
Use fenced code block for the table data.
|
|
64
|
+
## Example
|
|
67
65
|
|
|
68
66
|
``````
|
|
69
67
|
```table cols=4 header-rows=2 header-cols=1
|
|
@@ -127,7 +125,9 @@ c3| Q1 Sales
|
|
|
127
125
|
|
|
128
126
|
## Documentation
|
|
129
127
|
|
|
130
|
-
The table is expressed in a fenced code block.
|
|
128
|
+
The table is expressed in a fenced code block. The [info-string](https://spec.commonmark.org/0.31.2/#info-string) is parsed as [TableSpec](#tablespec), which defines the properties of the table.
|
|
129
|
+
|
|
130
|
+
Then, the cells are defined from left-top to right-bottom.
|
|
131
131
|
|
|
132
132
|
- A line that starts with `|` starts a new cell.
|
|
133
133
|
- The cell content is parsed as Markdown.
|
|
@@ -136,9 +136,7 @@ The table is expressed in a fenced code block.
|
|
|
136
136
|
A cell marker can include directives that control the cell’s properties.
|
|
137
137
|
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
The [info-string](https://spec.commonmark.org/0.31.2/#info-string) of the fenced code block is parsed as TableSpec.
|
|
139
|
+
<h3 id="tablespec">TableSpec (Table Definition)</h3>
|
|
142
140
|
|
|
143
141
|
<table>
|
|
144
142
|
<tr>
|
|
@@ -159,12 +157,12 @@ cols="1,1,2" // 3 columns, 1:1:2 ratio</pre>
|
|
|
159
157
|
<tr>
|
|
160
158
|
<td>header-cols</td>
|
|
161
159
|
<td>number</td>
|
|
162
|
-
<td>Number of header columns (rendered
|
|
160
|
+
<td>Number of header columns (rendered with <th>)</td>
|
|
163
161
|
</tr>
|
|
164
162
|
<tr>
|
|
165
163
|
<td>header-rows</td>
|
|
166
164
|
<td>number</td>
|
|
167
|
-
<td>Number of header rows (rendered
|
|
165
|
+
<td>Number of header rows (rendered with <thead> and <th>)</td>
|
|
168
166
|
</tr>
|
|
169
167
|
<tr>
|
|
170
168
|
<td>class</td>
|
|
@@ -180,7 +178,7 @@ cols="1,1,2" // 3 columns, 1:1:2 ratio</pre>
|
|
|
180
178
|
<td>format</td>
|
|
181
179
|
<td>string</td>
|
|
182
180
|
<td>
|
|
183
|
-
<p>Use alternative table syntax. </p>
|
|
181
|
+
<p>Use alternative table syntax (advTable only). </p>
|
|
184
182
|
<ul>
|
|
185
183
|
<li><code>csv</code> : parse text as csv</li>
|
|
186
184
|
<li><code>tsv</code> : parse text as tsv</li>
|
|
@@ -191,11 +189,7 @@ cols="1,1,2" // 3 columns, 1:1:2 ratio</pre>
|
|
|
191
189
|
|
|
192
190
|
<h3 id="colspec">ColSpec (Column Definition)</h3>
|
|
193
191
|
|
|
194
|
-
<code>ColSpec</code> is a comma-separated
|
|
195
|
-
|
|
196
|
-
"1,1,1" 3 columns, 1:1:1 ratio
|
|
197
|
-
"30%,15,30,60" 4 columns, 3:1:2:4 ratio
|
|
198
|
-
"<100px,,>25%" 3 columns, 100px-auto-25% with alignment directives
|
|
192
|
+
<code>ColSpec</code> is a comma-separated directives to set column's properties.
|
|
199
193
|
|
|
200
194
|
<table>
|
|
201
195
|
<tr>
|
|
@@ -215,11 +209,7 @@ cols="1,1,2" // 3 columns, 1:1:2 ratio</pre>
|
|
|
215
209
|
</tr>
|
|
216
210
|
<tr>
|
|
217
211
|
<td><<br>^<br>></td>
|
|
218
|
-
<td>
|
|
219
|
-
Left-aligned<br>
|
|
220
|
-
Center-aligned<br>
|
|
221
|
-
Right-aligned<br>
|
|
222
|
-
</td>
|
|
212
|
+
<td>Left-aligned<br>Center-aligned<br>Right-aligned</td>
|
|
223
213
|
</tr>
|
|
224
214
|
</table>
|
|
225
215
|
|
|
@@ -252,6 +242,7 @@ cols="1,1,2" // 3 columns, 1:1:2 ratio</pre>
|
|
|
252
242
|
|
|
253
243
|
|
|
254
244
|
|
|
245
|
+
|
|
255
246
|
## More Examples
|
|
256
247
|
|
|
257
248
|
|
|
@@ -264,7 +255,7 @@ cols="1,1,2" // 3 columns, 1:1:2 ratio</pre>
|
|
|
264
255
|
|
|
265
256
|
r3| Fruits
|
|
266
257
|
| Apple
|
|
267
|
-
|
|
258
|
+
^| $1.00
|
|
268
259
|
| A smooth, round fruit with shiny red skin.
|
|
269
260
|
|
|
270
261
|
| Banana
|
package/RELEASE.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
# Release Log
|
|
3
|
+
|
|
4
|
+
## 0.2.3 (2026-02-10)
|
|
5
|
+
|
|
6
|
+
- Fix: colspec with 1 column not properly parsed
|
|
7
|
+
- Fix: alignment directive in tableSpec was unused
|
|
8
|
+
|
|
9
|
+
## 0.2.2 (2026-02-08)
|
|
10
|
+
|
|
11
|
+
- Fix: output was sometimes wrong when table attrs were wrapped in quotes
|
|
12
|
+
- Fix: output was wrong when all columns were header without body cells
|
|
13
|
+
|
|
14
|
+
## 0.2.1 (2026-02-08)
|
|
15
|
+
|
|
16
|
+
- Fix: width field not properly parsed
|
|
17
|
+
|
|
18
|
+
## 0.2.0 (2026-02-07)
|
|
19
|
+
|
|
20
|
+
- New: Support setting table and column width
|
|
21
|
+
- New: Support Quoted classnames with space delimitors
|
|
22
|
+
- Fix: Prevent plugin crashing on invalid syntax
|
|
23
|
+
- Change: Removed support to change language names, except advTable plugin.
|
|
24
|
+
|
|
25
|
+
## 0.1.2 b2 (2025-05-20)
|
|
26
|
+
|
|
27
|
+
- Updated project structure. No code change.
|
|
28
|
+
|
|
29
|
+
## 0.1.1 b1 (2025-05-19)
|
|
30
|
+
|
|
31
|
+
- Fix: thead opened multiple times
|
|
32
|
+
- Fix: empty classname was being set
|
|
33
|
+
- Change: changed some option names
|
|
34
|
+
|
|
35
|
+
## 0.1.0 b0 (2025-05-19)
|
|
36
|
+
|
|
37
|
+
- Initial Release
|
package/lib/table-builder.js
CHANGED
|
@@ -13,7 +13,7 @@ export class TableBuilder {
|
|
|
13
13
|
return new TableBuilder(new state.md.block.State("", state.md, state.env, []), tableSpec);
|
|
14
14
|
}
|
|
15
15
|
get useColgroup() {
|
|
16
|
-
return this.tableSpec.
|
|
16
|
+
return this.tableSpec.colspecs.finemode;
|
|
17
17
|
}
|
|
18
18
|
get useTHead() {
|
|
19
19
|
return this.tableSpec.headerRows > 0;
|
|
@@ -64,9 +64,6 @@ export class TableBuilder {
|
|
|
64
64
|
if (this.useTHead && row === 0) {
|
|
65
65
|
this.startTHead();
|
|
66
66
|
}
|
|
67
|
-
else if (this.useTBody && row === this.tableSpec.headerRows) {
|
|
68
|
-
this.startTBody();
|
|
69
|
-
}
|
|
70
67
|
this.startRow();
|
|
71
68
|
}
|
|
72
69
|
const token = this.state.push(`${tx}_open`, tx, 1);
|
|
@@ -76,6 +73,9 @@ export class TableBuilder {
|
|
|
76
73
|
if (cell && cell.attr.colspan !== undefined) {
|
|
77
74
|
token.attrSet("colspan", cell.colspan.toString());
|
|
78
75
|
}
|
|
76
|
+
if (cell && this.tableSpec.colSpec(col).align !== undefined) {
|
|
77
|
+
token.attrSet("style", `text-align: ${this.tableSpec.colSpec(col).align}`);
|
|
78
|
+
}
|
|
79
79
|
if (cell && cell.attr.align !== undefined) {
|
|
80
80
|
token.attrSet("style", `text-align: ${cell.attr.align}`);
|
|
81
81
|
}
|
|
@@ -85,6 +85,7 @@ export class TableBuilder {
|
|
|
85
85
|
this.endRow();
|
|
86
86
|
if (this.useTHead && row == this.tableSpec.headerRows - 1) {
|
|
87
87
|
this.endTHead();
|
|
88
|
+
this.startTBody();
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
}
|
package/lib/table.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
type HAlign = "left" | "center" | "right";
|
|
2
|
-
|
|
2
|
+
declare const tableAttrKeys: readonly ["cols", "class", "header-rows", "header-cols", "width", "format"];
|
|
3
|
+
type TableAttrKeys = typeof tableAttrKeys[number];
|
|
3
4
|
export type TableAttr = {
|
|
4
5
|
[key in TableAttrKeys]?: string;
|
|
5
6
|
} & {
|
|
@@ -30,13 +31,15 @@ export declare class TableSpec {
|
|
|
30
31
|
readonly colspecs: ColSpecs;
|
|
31
32
|
constructor(attr: TableAttr);
|
|
32
33
|
get numCols(): number;
|
|
34
|
+
colSpec(col: number): ColumnAttr;
|
|
33
35
|
static parseClass(classnames: string): string[];
|
|
34
36
|
static parseInfoString(info: string): TableAttr;
|
|
35
|
-
static awareKeys(): TableAttrKeys[];
|
|
37
|
+
static awareKeys(): readonly TableAttrKeys[];
|
|
36
38
|
}
|
|
37
39
|
export declare class ColSpecs {
|
|
38
40
|
readonly numCols: number;
|
|
39
41
|
readonly specs: readonly ColumnAttr[];
|
|
42
|
+
readonly finemode: boolean;
|
|
40
43
|
constructor(colspec: string);
|
|
41
44
|
colSpec(col: number): ColumnAttr;
|
|
42
45
|
colWidth(col: number): ColWidth;
|
package/lib/table.js
CHANGED
|
@@ -10,6 +10,14 @@ const cssUnits = [
|
|
|
10
10
|
"dvw", "dvh", "dvi", "dvb", "dvmin", "dvmax",
|
|
11
11
|
"cqw", "cqh", "cqi", "cqb", "cqmin", "cqmax"
|
|
12
12
|
];
|
|
13
|
+
const tableAttrKeys = [
|
|
14
|
+
"cols",
|
|
15
|
+
"class",
|
|
16
|
+
"header-rows",
|
|
17
|
+
"header-cols",
|
|
18
|
+
"width",
|
|
19
|
+
"format"
|
|
20
|
+
];
|
|
13
21
|
export class ColWidth {
|
|
14
22
|
text;
|
|
15
23
|
constructor(text) {
|
|
@@ -54,6 +62,9 @@ export class TableSpec {
|
|
|
54
62
|
get numCols() {
|
|
55
63
|
return this.colspecs.numCols;
|
|
56
64
|
}
|
|
65
|
+
colSpec(col) {
|
|
66
|
+
return this.colspecs.colSpec(col);
|
|
67
|
+
}
|
|
57
68
|
static parseClass(classnames) {
|
|
58
69
|
return unwrapLiteral(classnames, "\"")
|
|
59
70
|
.split(/[\s,]/)
|
|
@@ -92,7 +103,7 @@ export class TableSpec {
|
|
|
92
103
|
const key = consume();
|
|
93
104
|
consume("=");
|
|
94
105
|
const value = consume();
|
|
95
|
-
result[key] = value;
|
|
106
|
+
result[key] = unwrapLiteral(value, "\"");
|
|
96
107
|
}
|
|
97
108
|
else {
|
|
98
109
|
consume();
|
|
@@ -109,33 +120,30 @@ export class TableSpec {
|
|
|
109
120
|
}
|
|
110
121
|
}
|
|
111
122
|
static awareKeys() {
|
|
112
|
-
|
|
113
|
-
cols: "",
|
|
114
|
-
align: "",
|
|
115
|
-
"header-cols": "",
|
|
116
|
-
"header-rows": "",
|
|
117
|
-
class: "",
|
|
118
|
-
width: "",
|
|
119
|
-
format: ""
|
|
120
|
-
};
|
|
121
|
-
return Object.keys(k);
|
|
123
|
+
return tableAttrKeys;
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
126
|
export class ColSpecs {
|
|
125
127
|
numCols;
|
|
126
128
|
specs;
|
|
129
|
+
finemode = false;
|
|
127
130
|
constructor(colspec) {
|
|
128
131
|
if (colspec.startsWith("\"") || colspec.includes(",")) {
|
|
129
132
|
const specs = unwrapLiteral(colspec, "\"").split(",");
|
|
130
133
|
this.numCols = Math.max(1, specs.length);
|
|
131
134
|
this.specs = specs.map(ColSpecs.parseColSpec);
|
|
135
|
+
this.finemode = true;
|
|
132
136
|
}
|
|
133
|
-
else if (/^\d
|
|
137
|
+
else if (/^\d+$/.test(colspec)) {
|
|
134
138
|
this.numCols = Math.max(1, parseInt(colspec, 10));
|
|
135
139
|
this.specs = Array(this.numCols).fill({});
|
|
136
140
|
}
|
|
141
|
+
else if (/^\d+/.test(colspec)) {
|
|
142
|
+
this.numCols = 1;
|
|
143
|
+
this.specs = [ColSpecs.parseColSpec(colspec)];
|
|
144
|
+
}
|
|
137
145
|
else {
|
|
138
|
-
this.numCols =
|
|
146
|
+
this.numCols = 1;
|
|
139
147
|
this.specs = Array(this.numCols).fill({});
|
|
140
148
|
}
|
|
141
149
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-it-adv-table",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Markdown syntax extension for better table support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"types": "lib/index.d.ts",
|
|
24
24
|
"files": [
|
|
25
25
|
"lib/**/*.js",
|
|
26
|
-
"lib/**/*.d.ts"
|
|
26
|
+
"lib/**/*.d.ts",
|
|
27
|
+
"RELEASE.md"
|
|
27
28
|
],
|
|
28
29
|
"scripts": {
|
|
29
30
|
"build": "tsc",
|
|
@@ -34,9 +35,9 @@
|
|
|
34
35
|
"lint:fix": "eslint src --fix"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@cobapen/eslint-config": "^0.5.
|
|
38
|
+
"@cobapen/eslint-config": "^0.5.1",
|
|
38
39
|
"@types/markdown-it": "^14.1.2",
|
|
39
|
-
"@types/node": "^25.2.
|
|
40
|
+
"@types/node": "^25.2.2",
|
|
40
41
|
"@vitest/coverage-v8": "^4.0.18",
|
|
41
42
|
"eslint": "^9.39.2",
|
|
42
43
|
"markdown-it": "^14.1.0",
|