@markdoc/markdoc 0.3.4 → 0.3.5
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/dist/index.js +10 -5
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +10 -5
- package/dist/index.mjs.map +2 -2
- package/dist/src/formatter.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/formatter.test.ts +4 -4
- package/src/formatter.ts +16 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA4B,IAAI,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAE/E,aAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA4B,IAAI,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAE/E,aAAK,OAAO,GAAG;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAsdF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAIlE"}
|
package/package.json
CHANGED
package/src/formatter.test.ts
CHANGED
|
@@ -376,10 +376,10 @@ Yes!
|
|
|
376
376
|
{% /table %}
|
|
377
377
|
`;
|
|
378
378
|
const expected = `
|
|
379
|
-
| Syntax
|
|
380
|
-
|
|
|
381
|
-
| Header
|
|
382
|
-
| Paragraph
|
|
379
|
+
| Syntax | Description |
|
|
380
|
+
| --------- | ----------- |
|
|
381
|
+
| Header | Title |
|
|
382
|
+
| Paragraph | Text |
|
|
383
383
|
|
|
384
384
|
{% table %}
|
|
385
385
|
- One {% align="middle" %}
|
package/src/formatter.ts
CHANGED
|
@@ -382,20 +382,28 @@ function* formatNode(n: Node, o: Options = {}) {
|
|
|
382
382
|
}
|
|
383
383
|
yield NL;
|
|
384
384
|
} else {
|
|
385
|
-
|
|
386
|
-
const [head, ...rows] = table as string[][];
|
|
385
|
+
const widths: number[] = [];
|
|
387
386
|
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
387
|
+
for (const row of table) {
|
|
388
|
+
for (let i = 0; i < row.length; i++) {
|
|
389
|
+
widths[i] = widths[i]
|
|
390
|
+
? Math.max(widths[i], row[i].length)
|
|
391
|
+
: row[i].length;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
391
394
|
|
|
392
|
-
|
|
395
|
+
const [head, ...rows] = table as string[][];
|
|
396
|
+
|
|
397
|
+
yield NL;
|
|
398
|
+
yield* formatTableRow(
|
|
399
|
+
head.map((cell, i) => cell + SPACE.repeat(widths[i] - cell.length))
|
|
400
|
+
);
|
|
393
401
|
yield NL;
|
|
394
|
-
yield* formatTableRow(head.map(() => '-'.repeat(
|
|
402
|
+
yield* formatTableRow(head.map((cell, i) => '-'.repeat(widths[i])));
|
|
395
403
|
yield NL;
|
|
396
404
|
for (const row of rows) {
|
|
397
405
|
yield* formatTableRow(
|
|
398
|
-
row.map((
|
|
406
|
+
row.map((cell, i) => cell + SPACE.repeat(widths[i] - cell.length))
|
|
399
407
|
);
|
|
400
408
|
yield NL;
|
|
401
409
|
}
|