@effected/markdown 0.4.0 → 0.4.2

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.
@@ -115,10 +115,7 @@ const phrasingText = (nodes) => {
115
115
  case "strong":
116
116
  case "delete":
117
117
  case "link":
118
- case "linkReference":
119
- out += phrasingText(node.children);
120
- break;
121
- default: break;
118
+ case "linkReference": out += phrasingText(node.children);
122
119
  }
123
120
  return out;
124
121
  };
@@ -340,7 +337,6 @@ var MarkdownDocument = class MarkdownDocument extends Schema.Class("MarkdownDocu
340
337
  });
341
338
  break;
342
339
  }
343
- default: break;
344
340
  }
345
341
  });
346
342
  return entries;
package/MarkdownNode.js CHANGED
@@ -460,7 +460,7 @@ var List = class extends Schema.Class("List")({
460
460
  ordered: Schema.optionalKey(Schema.Boolean),
461
461
  start: Schema.optionalKey(Schema.Number),
462
462
  spread: Schema.optionalKey(Schema.Boolean),
463
- children: Schema.Array(Schema.suspend(() => ListItem)),
463
+ children: Schema.Array(Schema.suspend(() => ListContent)),
464
464
  position: NodePosition,
465
465
  bulletChar: Schema.optionalKey(BulletChar),
466
466
  delimiter: Schema.optionalKey(ListDelimiter)
@@ -499,9 +499,19 @@ var TableCell = class extends Schema.Class("TableCell")({
499
499
  * content — the cells in a {@link TableRow}. A one-member union, kept because
500
500
  * mdast names the category.
501
501
  *
502
+ * A REAL `Schema.Union`, not a bare suspended class reference, and the
503
+ * wrapper is load-bearing: `make` passes an already-constructed class
504
+ * instance through a union member untouched, while a class-typed field
505
+ * re-runs construction on every element of the array. On a 30k-row table
506
+ * that re-construction was 1137ms for the single `Table.make` call against
507
+ * 9ms through the union (measured; the pathological suite's "tables" case is
508
+ * the regression instrument). The `children` fields of `TableRow`, `Table`
509
+ * and `List` point at these category unions for exactly that reason — do not
510
+ * "simplify" them back to the member class.
511
+ *
502
512
  * @public
503
513
  */
504
- const RowContent = Schema.suspend(() => TableCell);
514
+ const RowContent = Schema.suspend(() => Schema.Union([TableCell]));
505
515
  /**
506
516
  * TableRow — one row of a {@link Table}: the labels of the columns if it is
507
517
  * the table's first row, a data row otherwise.
@@ -510,17 +520,18 @@ const RowContent = Schema.suspend(() => TableCell);
510
520
  */
511
521
  var TableRow = class extends Schema.Class("TableRow")({
512
522
  type: Schema.tag("tableRow"),
513
- children: Schema.Array(Schema.suspend(() => TableCell)),
523
+ children: Schema.Array(Schema.suspend(() => RowContent)),
514
524
  position: NodePosition
515
525
  }) {};
516
526
  /**
517
527
  * The union of every node that may appear where mdast expects **table**
518
528
  * content — the rows in a {@link Table}. A one-member union, kept because
519
- * mdast names the category.
529
+ * mdast names the category — and a real `Schema.Union` for the construction
530
+ * pass-through documented on `RowContent`.
520
531
  *
521
532
  * @public
522
533
  */
523
- const TableContent = Schema.suspend(() => TableRow);
534
+ const TableContent = Schema.suspend(() => Schema.Union([TableRow]));
524
535
  /**
525
536
  * Table — GFM two-dimensional data.
526
537
  *
@@ -534,7 +545,7 @@ const TableContent = Schema.suspend(() => TableRow);
534
545
  var Table = class extends Schema.Class("Table")({
535
546
  type: Schema.tag("table"),
536
547
  align: Schema.optionalKey(Schema.Array(Schema.NullOr(TableAlign))),
537
- children: Schema.Array(Schema.suspend(() => TableRow)),
548
+ children: Schema.Array(Schema.suspend(() => TableContent)),
538
549
  position: NodePosition
539
550
  }) {};
540
551
  /**
@@ -563,11 +574,12 @@ const FlowContent = Schema.suspend(() => Schema.Union([
563
574
  /**
564
575
  * The union of every node that may appear where mdast expects **list**
565
576
  * content. A one-member union, kept because mdast names the category and
566
- * later dialects widen it.
577
+ * later dialects widen it — and a real `Schema.Union` for the construction
578
+ * pass-through documented on `RowContent`.
567
579
  *
568
580
  * @public
569
581
  */
570
- const ListContent = Schema.suspend(() => ListItem);
582
+ const ListContent = Schema.suspend(() => Schema.Union([ListItem]));
571
583
  /**
572
584
  * The frontmatter formats the capture recognizes, keyed by their opening
573
585
  * fence: `---` is yaml, `+++` is toml and `---json` is json.
package/index.d.ts CHANGED
@@ -540,6 +540,16 @@ declare class TableCell extends TableCell_base {}
540
540
  * content — the cells in a {@link TableRow}. A one-member union, kept because
541
541
  * mdast names the category.
542
542
  *
543
+ * A REAL `Schema.Union`, not a bare suspended class reference, and the
544
+ * wrapper is load-bearing: `make` passes an already-constructed class
545
+ * instance through a union member untouched, while a class-typed field
546
+ * re-runs construction on every element of the array. On a 30k-row table
547
+ * that re-construction was 1137ms for the single `Table.make` call against
548
+ * 9ms through the union (measured; the pathological suite's "tables" case is
549
+ * the regression instrument). The `children` fields of `TableRow`, `Table`
550
+ * and `List` point at these category unions for exactly that reason — do not
551
+ * "simplify" them back to the member class.
552
+ *
543
553
  * @public
544
554
  */
545
555
  declare const RowContent: Schema.Codec<RowContent>;
@@ -564,7 +574,8 @@ declare class TableRow extends TableRow_base {}
564
574
  /**
565
575
  * The union of every node that may appear where mdast expects **table**
566
576
  * content — the rows in a {@link Table}. A one-member union, kept because
567
- * mdast names the category.
577
+ * mdast names the category — and a real `Schema.Union` for the construction
578
+ * pass-through documented on `RowContent`.
568
579
  *
569
580
  * @public
570
581
  */
@@ -615,7 +626,8 @@ type FlowContent = Blockquote | Code | Definition | FootnoteDefinition | Heading
615
626
  /**
616
627
  * The union of every node that may appear where mdast expects **list**
617
628
  * content. A one-member union, kept because mdast names the category and
618
- * later dialects widen it.
629
+ * later dialects widen it — and a real `Schema.Union` for the construction
630
+ * pass-through documented on `RowContent`.
619
631
  *
620
632
  * @public
621
633
  */
@@ -20,6 +20,22 @@ const reLinkLabel = /^\[(?:[^\\[\]]|\\.){0,1000}\]/s;
20
20
  * between seconds and minutes.
21
21
  */
22
22
  const isWhitespaceCode = (code) => code === 32 || code === 9 || code === 10 || code === 11 || code === 12 || code === 13;
23
+ /**
24
+ * The most `(` a bare link destination may hold open at once.
25
+ *
26
+ * cmark's `MAX_LINK_DEST_PARENS` bound in `manual_scan_link_url`, and the
27
+ * limit the spec explicitly sanctions ("Implementations may impose limits on
28
+ * parentheses nesting to avoid performance issues, but at least three levels
29
+ * of nesting should be supported"). Without it the bare-destination walk is
30
+ * the engine's one quadratic: on `"[a](b".repeat(n)` there is no whitespace
31
+ * and no unbalanced `)` to stop at, so every failed inline-link attempt
32
+ * scanned to the end of the subject — O(n) per `]`, O(n^2) overall. With the
33
+ * cap a failed attempt stops at the 33rd `(`, a constant distance, and the
34
+ * pathological suite's "unclosed links B" runs linear. commonmark.js@0.31.2
35
+ * has no such cap and shares the quadratic; the C reference is the authority
36
+ * here.
37
+ */
38
+ const MAX_LINK_DESTINATION_PARENS = 32;
23
39
  const C_BACKSLASH = 92;
24
40
  const C_COLON = 58;
25
41
  const C_LESSTHAN = 60;
@@ -81,6 +97,7 @@ var ReferenceScanner = class {
81
97
  } else if (code === C_OPEN_PAREN) {
82
98
  this.pos += 1;
83
99
  openParens += 1;
100
+ if (openParens > MAX_LINK_DESTINATION_PARENS) return;
84
101
  } else if (code === C_CLOSE_PAREN) {
85
102
  if (openParens < 1) break;
86
103
  this.pos += 1;
@@ -291,7 +291,6 @@ const serializeInlines = (children, context, state, startsLine, junctionGuard) =
291
291
  case "footnoteReference":
292
292
  out += `[^${escapeLabel(child.label ?? child.identifier)}]`;
293
293
  atLineStart = false;
294
- break;
295
294
  }
296
295
  index += 1;
297
296
  unguard(state);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/markdown",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "private": false,
5
5
  "description": "CommonMark and GFM markdown parse, edit and transform schemas for Effect",
6
6
  "keywords": [
@@ -39,9 +39,9 @@
39
39
  "./package.json": "./package.json"
40
40
  },
41
41
  "peerDependencies": {
42
- "@effected/jsonc": "~0.5.1",
43
- "@effected/toml": "~0.3.1",
44
- "@effected/yaml": "~0.6.0",
42
+ "@effected/jsonc": "^0.5.2",
43
+ "@effected/toml": "^0.3.2",
44
+ "@effected/yaml": "^0.6.1",
45
45
  "effect": "4.0.0-beta.101"
46
46
  },
47
47
  "peerDependenciesMeta": {