@readme/markdown 11.7.5 → 11.7.7

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 });
@@ -88437,9 +88457,12 @@ function extractMagicBlocks(markdown) {
88437
88457
  const blocks = [];
88438
88458
  let index = 0;
88439
88459
  const replaced = markdown.replace(MAGIC_BLOCK_REGEX, match => {
88440
- // Use backticks so it becomes a code span, preventing remarkParse from
88441
- // parsing special characters in the token as markdown syntax
88442
- const token = `\`__MAGIC_BLOCK_${index}__\``;
88460
+ /**
88461
+ * - Use backticks so it becomes a code span, preventing remarkParse from parsing
88462
+ * special characters in the token as markdown syntax
88463
+ * - Prepend a newline to the token to ensure it is parsed as a block level node
88464
+ */
88465
+ const token = `\n\`__MAGIC_BLOCK_${index}__\``;
88443
88466
  blocks.push({ token, raw: match });
88444
88467
  index += 1;
88445
88468
  return token;
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 });
@@ -108641,9 +108661,12 @@ function extractMagicBlocks(markdown) {
108641
108661
  const blocks = [];
108642
108662
  let index = 0;
108643
108663
  const replaced = markdown.replace(MAGIC_BLOCK_REGEX, match => {
108644
- // Use backticks so it becomes a code span, preventing remarkParse from
108645
- // parsing special characters in the token as markdown syntax
108646
- const token = `\`__MAGIC_BLOCK_${index}__\``;
108664
+ /**
108665
+ * - Use backticks so it becomes a code span, preventing remarkParse from parsing
108666
+ * special characters in the token as markdown syntax
108667
+ * - Prepend a newline to the token to ensure it is parsed as a block level node
108668
+ */
108669
+ const token = `\n\`__MAGIC_BLOCK_${index}__\``;
108647
108670
  blocks.push({ token, raw: match });
108648
108671
  index += 1;
108649
108672
  return token;