@readme/markdown 14.14.1 → 14.14.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.
@@ -0,0 +1,9 @@
1
+ import type { Node, TableCell } from 'mdast';
2
+ export declare const hasChildren: (node: Node) => node is Node & {
3
+ children: Node[];
4
+ };
5
+ /**
6
+ * Returns a copy of the cell's children with line breaks — `break` nodes and newlines inside
7
+ * text — rewritten to the `<br />` a single-line GFM pipe cell can carry.
8
+ */
9
+ export declare const normalizeCellChildrenForGfm: (cell: TableCell) => TableCell["children"];
@@ -20197,7 +20197,7 @@ const CONTINUE = true
20197
20197
  /**
20198
20198
  * Stop traversing immediately.
20199
20199
  */
20200
- const EXIT = false
20200
+ const lib_EXIT = false
20201
20201
 
20202
20202
  /**
20203
20203
  * Do not traverse this node’s children.
@@ -20311,7 +20311,7 @@ function visitParents(tree, test, visitor, reverse) {
20311
20311
  // @ts-expect-error: `visitor` is now a visitor.
20312
20312
  result = toResult(visitor(node, parents))
20313
20313
 
20314
- if (result[0] === EXIT) {
20314
+ if (result[0] === lib_EXIT) {
20315
20315
  return result
20316
20316
  }
20317
20317
  }
@@ -20328,7 +20328,7 @@ function visitParents(tree, test, visitor, reverse) {
20328
20328
 
20329
20329
  subresult = factory(child, offset, grandparents)()
20330
20330
 
20331
- if (subresult[0] === EXIT) {
20331
+ if (subresult[0] === lib_EXIT) {
20332
20332
  return subresult
20333
20333
  }
20334
20334
 
@@ -34035,7 +34035,7 @@ function formatHeadingAsSetext(node, state) {
34035
34035
  node.type === 'break'
34036
34036
  ) {
34037
34037
  literalWithBreak = true
34038
- return EXIT
34038
+ return lib_EXIT
34039
34039
  }
34040
34040
  })
34041
34041
 
@@ -52885,7 +52885,7 @@ const lib_CONTINUE = Symbol('continue')
52885
52885
  /**
52886
52886
  * Stop traversing immediately.
52887
52887
  */
52888
- const lib_EXIT = Symbol('exit')
52888
+ const estree_util_visit_lib_EXIT = Symbol('exit')
52889
52889
 
52890
52890
  /**
52891
52891
  * Do not traverse this node’s children.
@@ -52945,7 +52945,7 @@ function estree_util_visit_lib_visit(tree, visitor) {
52945
52945
  /** @type {ActionTuple} */
52946
52946
  const result = enter ? lib_toResult(enter(node, key, index, parents)) : []
52947
52947
 
52948
- if (result[0] === lib_EXIT) {
52948
+ if (result[0] === estree_util_visit_lib_EXIT) {
52949
52949
  return result
52950
52950
  }
52951
52951
 
@@ -52981,7 +52981,7 @@ function estree_util_visit_lib_visit(tree, visitor) {
52981
52981
  cIndex,
52982
52982
  grandparents
52983
52983
  )()
52984
- if (subresult[0] === lib_EXIT) return subresult
52984
+ if (subresult[0] === estree_util_visit_lib_EXIT) return subresult
52985
52985
  cIndex =
52986
52986
  typeof subresult[1] === 'number' ? subresult[1] : cIndex + 1
52987
52987
  } else {
@@ -52990,7 +52990,7 @@ function estree_util_visit_lib_visit(tree, visitor) {
52990
52990
  }
52991
52991
  } else if (nodelike(value)) {
52992
52992
  const subresult = build(value, cKey, undefined, grandparents)()
52993
- if (subresult[0] === lib_EXIT) return subresult
52993
+ if (subresult[0] === estree_util_visit_lib_EXIT) return subresult
52994
52994
  }
52995
52995
  }
52996
52996
  }
@@ -68773,7 +68773,7 @@ const hasNamedExport = (tree, name) => {
68773
68773
  node.data.estree.body[0].declaration.type === 'VariableDeclaration') {
68774
68774
  const { declarations } = node.data.estree.body[0].declaration;
68775
68775
  hasExport = !!declarations.find(declaration => 'name' in declaration.id && declaration.id.name === name);
68776
- return hasExport ? EXIT : CONTINUE;
68776
+ return hasExport ? lib_EXIT : CONTINUE;
68777
68777
  }
68778
68778
  });
68779
68779
  return hasExport;
@@ -69274,7 +69274,7 @@ const compatibilityTransfomer = () => tree => {
69274
69274
  const trimEmphasis = (node) => {
69275
69275
  lib_visit(node, 'text', child => {
69276
69276
  child.value = child.value.trim();
69277
- return EXIT;
69277
+ return lib_EXIT;
69278
69278
  });
69279
69279
  return node;
69280
69280
  };
@@ -100447,7 +100447,7 @@ const processTableNode = (node, index, parent, documentPosition) => {
100447
100447
  ((candidate.type === 'mdxJsxFlowElement' || candidate.type === 'mdxJsxTextElement') &&
100448
100448
  candidate.name === 'HTMLBlock'), () => {
100449
100449
  tableHasFlowContent = true;
100450
- return EXIT;
100450
+ return lib_EXIT;
100451
100451
  });
100452
100452
  // Re-parse text-only cells through markdown and detect flow content
100453
100453
  lib_visit(node, isTableCell, (cell) => {
@@ -100661,7 +100661,7 @@ const mdxish_tables_mdxishTables = () => tree => {
100661
100661
  if (tableNode.name !== 'Table' && tableNode.name !== 'table')
100662
100662
  return undefined;
100663
100663
  processTableNode(tableNode, index, parent, node.position);
100664
- return EXIT;
100664
+ return lib_EXIT;
100665
100665
  });
100666
100666
  }
100667
100667
  else if (node.value.startsWith('<table')) {
@@ -101147,13 +101147,13 @@ const visitor = (table, index, parent) => {
101147
101147
  let hasFlowContent = false;
101148
101148
  const tableCellVisitor = (cell) => {
101149
101149
  if (cell.children.length === 0)
101150
- return EXIT;
101150
+ return lib_EXIT;
101151
101151
  const content = cell.children.length === 1 && cell.children[0].type === 'paragraph'
101152
101152
  ? cell.children[0].children[0]
101153
101153
  : cell.children[0];
101154
101154
  // If cell is empty there's nothing to visit
101155
101155
  if (!content)
101156
- return EXIT;
101156
+ return lib_EXIT;
101157
101157
  // @note: Compatibility with RDMD. Ideally, I'd put this in a separate
101158
101158
  // transformer, but then there'd be some duplication.
101159
101159
  lib_visit(cell, 'break', (_, breakIndex, breakParent) => {
@@ -101161,12 +101161,12 @@ const visitor = (table, index, parent) => {
101161
101161
  });
101162
101162
  if (!(lib_phrasing(content) || content.type === 'plain') && content.type !== 'escape') {
101163
101163
  hasFlowContent = true;
101164
- return EXIT;
101164
+ return lib_EXIT;
101165
101165
  }
101166
101166
  lib_visit(cell, isLiteral, (node) => {
101167
101167
  if (node.value.match(/\n/)) {
101168
101168
  hasFlowContent = true;
101169
- return EXIT;
101169
+ return lib_EXIT;
101170
101170
  }
101171
101171
  });
101172
101172
  };
@@ -119381,7 +119381,7 @@ function media(state, node) {
119381
119381
  lib_visit(fragment, function (node) {
119382
119382
  if (node.type === 'link') {
119383
119383
  linkInFallbackContent = true
119384
- return EXIT
119384
+ return lib_EXIT
119385
119385
  }
119386
119386
  })
119387
119387
 
@@ -120905,7 +120905,7 @@ const trimEmphasis = (node, index, parent) => {
120905
120905
  trimmed = true;
120906
120906
  child.value = newValue;
120907
120907
  }
120908
- return EXIT;
120908
+ return lib_EXIT;
120909
120909
  });
120910
120910
  lib_visit(node, 'text', (child) => {
120911
120911
  const newValue = child.value.trimEnd();
@@ -120913,7 +120913,7 @@ const trimEmphasis = (node, index, parent) => {
120913
120913
  trimmed = true;
120914
120914
  child.value = newValue;
120915
120915
  }
120916
- return EXIT;
120916
+ return lib_EXIT;
120917
120917
  }, true);
120918
120918
  if (trimmed) {
120919
120919
  addSpaceBefore(index, parent);
@@ -126593,6 +126593,7 @@ const restoreBooleanProperties = () => tree => {
126593
126593
 
126594
126594
 
126595
126595
 
126596
+
126596
126597
  const SELF_CLOSING_JSX_REGEX = /^\s*<[A-Z][^>]*\/>\s*$/;
126597
126598
  const mdxish_tables_to_jsx_alignToStyle = (align) => {
126598
126599
  if (!align || align === 'left')
@@ -126608,6 +126609,38 @@ const mdxish_tables_to_jsx_alignToStyle = (align) => {
126608
126609
  };
126609
126610
  const mdxish_tables_to_jsx_isTableCell = (node) => ['tableHead', 'tableCell'].includes(node.type);
126610
126611
  const mdxish_tables_to_jsx_isLiteral = (node) => 'value' in node;
126612
+ /**
126613
+ * Block-level content that a single-line GFM cell cannot hold. `phrasing()` returns true
126614
+ * for inline types (text, emphasis, strong, link…), which are safe to keep.
126615
+ */
126616
+ const isFlowChild = (child) => {
126617
+ if (child.type === 'paragraph' || child.type === 'plain' || child.type === 'escape')
126618
+ return false;
126619
+ if (child.type === NodeTypes.variable)
126620
+ return false;
126621
+ if (phrasing(child))
126622
+ return false;
126623
+ if (child.type === 'html')
126624
+ return SELF_CLOSING_JSX_REGEX.test(child.value);
126625
+ return true;
126626
+ };
126627
+ /** A newline in a normalized cell (e.g. inside `inlineCode`) has no inline equivalent. */
126628
+ const containsLiteralNewline = (nodes) => nodes.some(node => (mdxish_tables_to_jsx_isLiteral(node) && node.value.includes('\n')) || (hasChildren(node) && containsLiteralNewline(node.children)));
126629
+ /** True when normalized cell content survives a single-line GFM pipe cell without losing structure. */
126630
+ const canCellBeGfm = (children) => {
126631
+ // Multiple paragraphs are distinct blocks; a single-line cell cannot keep them apart.
126632
+ if (children.filter(child => child.type === 'paragraph').length > 1)
126633
+ return false;
126634
+ if (children.some(isFlowChild))
126635
+ return false;
126636
+ return !containsLiteralNewline(children);
126637
+ };
126638
+ /** On the promote path a `break` would serialize as a dangling `\`, so collapse it to a newline. */
126639
+ const flattenBreaksToNewlines = (cell) => {
126640
+ visit(cell, 'break', (_, index, parent) => {
126641
+ parent.children.splice(index, 1, { type: 'text', value: '\n' });
126642
+ });
126643
+ };
126611
126644
  /**
126612
126645
  * Mdxish-specific version of `tablesToJsx`. Differs from the shared MDX version:
126613
126646
  *
@@ -126618,52 +126651,25 @@ const mdxish_tables_to_jsx_isLiteral = (node) => 'value' in node;
126618
126651
  */
126619
126652
  const mdxish_tables_to_jsx_mdxishTablesToJsx = () => tree => {
126620
126653
  visit(tree, (node) => ['table', 'tableau'].includes(node.type), (table, index, parent) => {
126621
- let hasFlowContent = false;
126654
+ const gfmCells = [];
126655
+ let requiresJsxTable = false;
126622
126656
  visit(table, mdxish_tables_to_jsx_isTableCell, (cell) => {
126623
- if (hasFlowContent || cell.children.length === 0)
126624
- return;
126625
- visit(cell, 'break', (_, breakIndex, breakParent) => {
126626
- breakParent.children.splice(breakIndex, 1, { type: 'text', value: '\n' });
126627
- });
126628
- // A cell with more than one paragraph child cannot be serialized as GFM
126629
- // (pipe tables are single-line per cell), so force JSX <Table> output to
126630
- // preserve paragraph separation.
126631
- const paragraphCount = cell.children.filter(child => child.type === 'paragraph').length;
126632
- if (paragraphCount > 1) {
126633
- hasFlowContent = true;
126634
- return;
126635
- }
126636
- // Check if any child is "flow" content (block-level) that requires JSX <Table>
126637
- // serialization instead of GFM. `phrasing()` from mdast-util-phrasing returns
126638
- // true for inline node types (text, emphasis, strong, link, etc.) which are
126639
- // safe to keep in GFM cells.
126640
- const hasFlowChild = cell.children.some(child => {
126641
- if (child.type === 'paragraph' || child.type === 'plain' || child.type === 'escape')
126642
- return false;
126643
- if (child.type === NodeTypes.variable)
126644
- return false;
126645
- if (phrasing(child))
126646
- return false;
126647
- if (child.type === 'html') {
126648
- return SELF_CLOSING_JSX_REGEX.test(child.value);
126649
- }
126650
- return true;
126651
- });
126652
- if (hasFlowChild) {
126653
- hasFlowContent = true;
126654
- }
126655
- if (!hasFlowContent) {
126656
- visit(cell, mdxish_tables_to_jsx_isLiteral, (node) => {
126657
- if (node.value.match(/\n/)) {
126658
- hasFlowContent = true;
126659
- }
126660
- });
126657
+ const normalized = normalizeCellChildrenForGfm(cell);
126658
+ if (!canCellBeGfm(normalized)) {
126659
+ requiresJsxTable = true;
126660
+ return EXIT;
126661
126661
  }
126662
+ gfmCells.push([cell, normalized]);
126663
+ return undefined;
126662
126664
  });
126663
- if (!hasFlowContent) {
126665
+ if (!requiresJsxTable) {
126666
+ gfmCells.forEach(([cell, children]) => {
126667
+ cell.children = children;
126668
+ });
126664
126669
  table.type = 'table';
126665
126670
  return;
126666
126671
  }
126672
+ visit(table, mdxish_tables_to_jsx_isTableCell, flattenBreaksToNewlines);
126667
126673
  const styles = table.align.map(mdxish_tables_to_jsx_alignToStyle);
126668
126674
  const head = {
126669
126675
  attributes: [],