@readme/markdown 11.7.4 → 11.7.6

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/main.js CHANGED
@@ -83028,13 +83028,30 @@ const rehypeToc = ({ components = {} }) => {
83028
83028
  };
83029
83029
  };
83030
83030
  const MAX_DEPTH = 2;
83031
- const getDepth = (el) => parseInt(el.tagName?.match(/^h(\d)/)[1], 10);
83031
+ /**
83032
+ * Get the depth of a heading element based on its tag name.
83033
+ *
83034
+ * ⚠️ Be extra defensive to non-heading elements somehow making it here. This
83035
+ * should not happen, but if it does, we avoid breaking TOC depth calculations
83036
+ * by returning `Infinity`, thus removing them from depth considerations.
83037
+ * @link https://linear.app/readme-io/issue/CX-2543/tabapay-toc-does-not-respect-headers-nesting
83038
+ *
83039
+ * @example
83040
+ * getDepth({ tagName: 'h1' }) // 1
83041
+ * getDepth({ tagName: 'h2' }) // 2
83042
+ */
83043
+ const getDepth = (el) => {
83044
+ if (!el.tagName)
83045
+ return Infinity;
83046
+ return parseInt(el.tagName?.match(/^h(\d)/)[1], 10);
83047
+ };
83032
83048
  /*
83033
83049
  * `tocToHast` consumes the list generated by `rehypeToc` and produces a hast
83034
83050
  * of nested lists to be rendered as a table of contents.
83035
83051
  */
83036
83052
  const tocToHast = (headings = []) => {
83037
- const min = Math.min(...headings.map(getDepth));
83053
+ const headingDepths = headings.map(getDepth);
83054
+ const min = Math.min(...headingDepths);
83038
83055
  const ast = hastscript_lib_h('ul');
83039
83056
  const stack = [ast];
83040
83057
  headings.forEach(heading => {
@@ -83065,7 +83082,10 @@ const tocHastToMdx = (toc, components) => {
83065
83082
  if (typeof toc === 'undefined')
83066
83083
  return '';
83067
83084
  const injected = toc.flatMap(node => {
83068
- return node.type === 'mdxJsxFlowElement' && node.name in components ? components[node.name] || [] : node;
83085
+ if (node.type === 'mdxJsxFlowElement') {
83086
+ return components[node.name] || [];
83087
+ }
83088
+ return node;
83069
83089
  });
83070
83090
  const tocHast = tocToHast(injected);
83071
83091
  return lib_mdx({ type: 'root', children: [tocHast] }, { hast: true });
@@ -88462,6 +88482,7 @@ function restoreMagicBlocks(replaced, blocks) {
88462
88482
 
88463
88483
 
88464
88484
 
88485
+
88465
88486
  /**
88466
88487
  * Removes Markdown and MDX comments.
88467
88488
  */
@@ -88471,7 +88492,20 @@ async function stripComments(doc, { mdx } = {}) {
88471
88492
  .use(remarkParse)
88472
88493
  .use(mdx ? remarkMdx : undefined)
88473
88494
  .use(stripCommentsTransformer)
88474
- .use(remarkStringify);
88495
+ .use(remarkStringify, mdx
88496
+ ? {}
88497
+ : {
88498
+ handlers: {
88499
+ // Preserve <<...>> variables without escaping any angle brackets.
88500
+ text(node, _, state, info) {
88501
+ // If text contains <<...>> pattern, return as is.
88502
+ if (new RegExp(variable_.VARIABLE_REGEXP).test(node.value))
88503
+ return node.value;
88504
+ // Otherwise, handle each text node normally.
88505
+ return state.safe(node.value, info);
88506
+ },
88507
+ },
88508
+ });
88475
88509
  const file = await processor.process(replaced);
88476
88510
  const stringified = String(file).trim();
88477
88511
  const restored = restoreMagicBlocks(stringified, blocks);
package/dist/main.node.js CHANGED
@@ -103232,13 +103232,30 @@ const rehypeToc = ({ components = {} }) => {
103232
103232
  };
103233
103233
  };
103234
103234
  const MAX_DEPTH = 2;
103235
- const getDepth = (el) => parseInt(el.tagName?.match(/^h(\d)/)[1], 10);
103235
+ /**
103236
+ * Get the depth of a heading element based on its tag name.
103237
+ *
103238
+ * ⚠️ Be extra defensive to non-heading elements somehow making it here. This
103239
+ * should not happen, but if it does, we avoid breaking TOC depth calculations
103240
+ * by returning `Infinity`, thus removing them from depth considerations.
103241
+ * @link https://linear.app/readme-io/issue/CX-2543/tabapay-toc-does-not-respect-headers-nesting
103242
+ *
103243
+ * @example
103244
+ * getDepth({ tagName: 'h1' }) // 1
103245
+ * getDepth({ tagName: 'h2' }) // 2
103246
+ */
103247
+ const getDepth = (el) => {
103248
+ if (!el.tagName)
103249
+ return Infinity;
103250
+ return parseInt(el.tagName?.match(/^h(\d)/)[1], 10);
103251
+ };
103236
103252
  /*
103237
103253
  * `tocToHast` consumes the list generated by `rehypeToc` and produces a hast
103238
103254
  * of nested lists to be rendered as a table of contents.
103239
103255
  */
103240
103256
  const tocToHast = (headings = []) => {
103241
- const min = Math.min(...headings.map(getDepth));
103257
+ const headingDepths = headings.map(getDepth);
103258
+ const min = Math.min(...headingDepths);
103242
103259
  const ast = hastscript_lib_h('ul');
103243
103260
  const stack = [ast];
103244
103261
  headings.forEach(heading => {
@@ -103269,7 +103286,10 @@ const tocHastToMdx = (toc, components) => {
103269
103286
  if (typeof toc === 'undefined')
103270
103287
  return '';
103271
103288
  const injected = toc.flatMap(node => {
103272
- return node.type === 'mdxJsxFlowElement' && node.name in components ? components[node.name] || [] : node;
103289
+ if (node.type === 'mdxJsxFlowElement') {
103290
+ return components[node.name] || [];
103291
+ }
103292
+ return node;
103273
103293
  });
103274
103294
  const tocHast = tocToHast(injected);
103275
103295
  return lib_mdx({ type: 'root', children: [tocHast] }, { hast: true });
@@ -108666,6 +108686,7 @@ function restoreMagicBlocks(replaced, blocks) {
108666
108686
 
108667
108687
 
108668
108688
 
108689
+
108669
108690
  /**
108670
108691
  * Removes Markdown and MDX comments.
108671
108692
  */
@@ -108675,7 +108696,20 @@ async function stripComments(doc, { mdx } = {}) {
108675
108696
  .use(remarkParse)
108676
108697
  .use(mdx ? remarkMdx : undefined)
108677
108698
  .use(stripCommentsTransformer)
108678
- .use(remarkStringify);
108699
+ .use(remarkStringify, mdx
108700
+ ? {}
108701
+ : {
108702
+ handlers: {
108703
+ // Preserve <<...>> variables without escaping any angle brackets.
108704
+ text(node, _, state, info) {
108705
+ // If text contains <<...>> pattern, return as is.
108706
+ if (new RegExp(dist.VARIABLE_REGEXP).test(node.value))
108707
+ return node.value;
108708
+ // Otherwise, handle each text node normally.
108709
+ return state.safe(node.value, info);
108710
+ },
108711
+ },
108712
+ });
108679
108713
  const file = await processor.process(replaced);
108680
108714
  const stringified = String(file).trim();
108681
108715
  const restored = restoreMagicBlocks(stringified, blocks);