@markdoc/markdoc 0.3.4 → 0.4.0

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.4.0",
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
  }
@@ -171,6 +171,9 @@ function peg$parse(input, options) {
171
171
  var peg$c15 = '-';
172
172
  var peg$c16 = '"';
173
173
  var peg$c17 = '\\';
174
+ var peg$c18 = 'n';
175
+ var peg$c19 = 'r';
176
+ var peg$c20 = 't';
174
177
 
175
178
  var peg$r0 = /^[$@]/;
176
179
  var peg$r1 = /^[0-9]/;
@@ -300,7 +303,16 @@ function peg$parse(input, options) {
300
303
  var peg$f28 = function (value) {
301
304
  return value.join('');
302
305
  };
303
- var peg$f29 = function (sequence) {
306
+ var peg$f29 = function () {
307
+ return '\n';
308
+ };
309
+ var peg$f30 = function () {
310
+ return '\r';
311
+ };
312
+ var peg$f31 = function () {
313
+ return '\t';
314
+ };
315
+ var peg$f32 = function (sequence) {
304
316
  return sequence;
305
317
  };
306
318
 
@@ -1711,7 +1723,7 @@ function peg$parse(input, options) {
1711
1723
  }
1712
1724
 
1713
1725
  function peg$parseValueStringEscapes() {
1714
- var s0, s1, s2;
1726
+ var s0, s1, s2, s3;
1715
1727
 
1716
1728
  var rule$expects = function (expected) {
1717
1729
  if (peg$silentFails === 0) peg$expect(expected);
@@ -1738,10 +1750,52 @@ function peg$parse(input, options) {
1738
1750
  } else {
1739
1751
  s2 = peg$FAILED;
1740
1752
  }
1753
+ if (s2 === peg$FAILED) {
1754
+ s2 = peg$currPos;
1755
+ if (input.charCodeAt(peg$currPos) === 110) {
1756
+ s3 = peg$c18;
1757
+ peg$currPos++;
1758
+ } else {
1759
+ s3 = peg$FAILED;
1760
+ }
1761
+ if (s3 !== peg$FAILED) {
1762
+ peg$savedPos = s2;
1763
+ s3 = peg$f29();
1764
+ }
1765
+ s2 = s3;
1766
+ if (s2 === peg$FAILED) {
1767
+ s2 = peg$currPos;
1768
+ if (input.charCodeAt(peg$currPos) === 114) {
1769
+ s3 = peg$c19;
1770
+ peg$currPos++;
1771
+ } else {
1772
+ s3 = peg$FAILED;
1773
+ }
1774
+ if (s3 !== peg$FAILED) {
1775
+ peg$savedPos = s2;
1776
+ s3 = peg$f30();
1777
+ }
1778
+ s2 = s3;
1779
+ if (s2 === peg$FAILED) {
1780
+ s2 = peg$currPos;
1781
+ if (input.charCodeAt(peg$currPos) === 116) {
1782
+ s3 = peg$c20;
1783
+ peg$currPos++;
1784
+ } else {
1785
+ s3 = peg$FAILED;
1786
+ }
1787
+ if (s3 !== peg$FAILED) {
1788
+ peg$savedPos = s2;
1789
+ s3 = peg$f31();
1790
+ }
1791
+ s2 = s3;
1792
+ }
1793
+ }
1794
+ }
1741
1795
  }
1742
1796
  if (s2 !== peg$FAILED) {
1743
1797
  peg$savedPos = s0;
1744
- s0 = peg$f29(s2);
1798
+ s0 = peg$f32(s2);
1745
1799
  } else {
1746
1800
  peg$currPos = s0;
1747
1801
  s0 = peg$FAILED;
@@ -162,7 +162,13 @@ ValueStringChars =
162
162
  [^\0-\x1F\x22\x5C] / ValueStringEscapes
163
163
 
164
164
  ValueStringEscapes =
165
- '\\' sequence:('"' / '\\') { return sequence; }
165
+ '\\' sequence:(
166
+ '"' /
167
+ '\\' /
168
+ 'n' { return '\n' } /
169
+ 'r' { return '\r' } /
170
+ 't' { return '\t' }
171
+ ) { return sequence; }
166
172
 
167
173
  Identifier 'identifier' =
168
174
  $([a-zA-Z0-9_-]+)
package/src/schema.ts CHANGED
@@ -145,7 +145,7 @@ export const td: Schema = {
145
145
  export const th: Schema = {
146
146
  render: 'th',
147
147
  attributes: {
148
- width: { type: Number },
148
+ width: { type: String },
149
149
  align: { type: String },
150
150
  colspan: { type: Number, render: 'colSpan' },
151
151
  rowspan: { type: Number, render: 'rowSpan' },