@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.
@@ -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;AA8cF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAIlE"}
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markdoc/markdoc",
3
3
  "author": "Ryan Paul",
4
- "version": "0.3.4",
4
+ "version": "0.3.5",
5
5
  "description": "A text markup language for documentation",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -376,10 +376,10 @@ Yes!
376
376
  {% /table %}
377
377
  `;
378
378
  const expected = `
379
- | Syntax | Description |
380
- | ----------- | ----------- |
381
- | Header | Title |
382
- | Paragraph | Text |
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
- yield NL;
386
- const [head, ...rows] = table as string[][];
385
+ const widths: number[] = [];
387
386
 
388
- const ml = table
389
- .map((arr) => arr.map((s: string) => s.length).reduce(max))
390
- .reduce(max);
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
- yield* formatTableRow(head.map((h) => h + SPACE.repeat(ml - h.length)));
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(ml)));
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((r) => r + SPACE.repeat(ml - r.length))
406
+ row.map((cell, i) => cell + SPACE.repeat(widths[i] - cell.length))
399
407
  );
400
408
  yield NL;
401
409
  }