@adobe/helix-markdown-support 4.0.2 → 4.0.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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/gridtable/to-markdown.js +30 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [4.0.3](https://github.com/adobe/helix-markdown-support/compare/v4.0.2...v4.0.3) (2022-09-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* more improvements ([7d348e0](https://github.com/adobe/helix-markdown-support/commit/7d348e0cfdde11ab04f26c40fa7f9739787b9030))
|
|
7
|
+
|
|
1
8
|
## [4.0.2](https://github.com/adobe/helix-markdown-support/compare/v4.0.1...v4.0.2) (2022-09-03)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -41,7 +41,7 @@ function spanWidth(cols, idx, cell) {
|
|
|
41
41
|
export function lineWrapTextHandler(node, parent, context, safeOptions) {
|
|
42
42
|
const textNode = {
|
|
43
43
|
...node,
|
|
44
|
-
value: node.value.replace(
|
|
44
|
+
value: node.value.replace(/[ \t\v\r\n]/g, ' '),
|
|
45
45
|
};
|
|
46
46
|
let value = textHandler(textNode, parent, context, safeOptions);
|
|
47
47
|
const { lineWidth } = context.options;
|
|
@@ -123,11 +123,9 @@ class Table {
|
|
|
123
123
|
row = row || this.lastRow;
|
|
124
124
|
row.cells.push(cell);
|
|
125
125
|
for (let i = 1; i < cell.colSpan; i += 1) {
|
|
126
|
-
row.cells.push({
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (cell.colSpan > 1) {
|
|
130
|
-
row.cells[row.cells.length - 1].align = cell.align;
|
|
126
|
+
row.cells.push({
|
|
127
|
+
align: cell.align,
|
|
128
|
+
});
|
|
131
129
|
}
|
|
132
130
|
}
|
|
133
131
|
|
|
@@ -166,6 +164,7 @@ class Table {
|
|
|
166
164
|
toMarkdown(context) {
|
|
167
165
|
// populate the matrix with the rowspans and compute max width
|
|
168
166
|
// (the empty cells for the colspans are already created during insert).
|
|
167
|
+
let realNumCols = 0;
|
|
169
168
|
const cols = [];
|
|
170
169
|
for (let y = 0; y < this.rows.length; y += 1) {
|
|
171
170
|
const row = this.rows[y];
|
|
@@ -178,6 +177,9 @@ class Table {
|
|
|
178
177
|
cols[x] = col;
|
|
179
178
|
}
|
|
180
179
|
const cell = row.cells[x];
|
|
180
|
+
if (cell.tree) {
|
|
181
|
+
realNumCols = Math.max(realNumCols, x + 1);
|
|
182
|
+
}
|
|
181
183
|
if (cell.rowSpan > 1) {
|
|
182
184
|
// insert colspan amount of null cells below
|
|
183
185
|
for (let i = 1; i < cell.rowSpan; i += 1) {
|
|
@@ -190,6 +192,25 @@ class Table {
|
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
194
|
}
|
|
195
|
+
|
|
196
|
+
// now trim tailing colspans
|
|
197
|
+
if (cols.length > realNumCols) {
|
|
198
|
+
cols.length = realNumCols;
|
|
199
|
+
for (const { cells } of this.rows) {
|
|
200
|
+
if (cells.length > realNumCols) {
|
|
201
|
+
cells.length = realNumCols;
|
|
202
|
+
// find trailing colspan
|
|
203
|
+
let x = cells.length - 1;
|
|
204
|
+
while (x >= 0 && !cells[x].tree) {
|
|
205
|
+
x -= 1;
|
|
206
|
+
}
|
|
207
|
+
if (x >= 0) {
|
|
208
|
+
cells[x].colSpan = realNumCols - x;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
193
214
|
const numCols = cols.length;
|
|
194
215
|
|
|
195
216
|
// add empty cells if needed
|
|
@@ -385,17 +406,18 @@ class Table {
|
|
|
385
406
|
}
|
|
386
407
|
|
|
387
408
|
// add last grid line
|
|
409
|
+
const d = this.rows.length === this.headerSize ? '=' : '-'; // special case: only header
|
|
388
410
|
const grid = [];
|
|
389
411
|
const lastRow = this.rows[this.rows.length - 1];
|
|
390
412
|
for (let x = 0; x < cols.length; x += 1) {
|
|
391
413
|
const col = cols[x];
|
|
392
414
|
// if the cell above was a colspan, and we are on the last line, don't draw the `+`
|
|
393
415
|
const aboveCell = lastRow.cells[x];
|
|
394
|
-
let c = aboveCell.tree || aboveCell.linked ? gtVLineEnds :
|
|
416
|
+
let c = aboveCell.tree || aboveCell.linked ? gtVLineEnds : d;
|
|
395
417
|
if (x === 0) {
|
|
396
418
|
c = '+';
|
|
397
419
|
}
|
|
398
|
-
grid.push(`${c}${
|
|
420
|
+
grid.push(`${c}${d.repeat(col.width - 1)}`);
|
|
399
421
|
}
|
|
400
422
|
lines.push(`${grid.join('')}+`);
|
|
401
423
|
|