@readme/markdown 14.1.1 → 14.1.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.
package/dist/main.js CHANGED
@@ -87611,7 +87611,12 @@ const tocHastToMdx = (toc, components, variables) => {
87611
87611
 
87612
87612
 
87613
87613
  const sanitizeSchema = cjs_default()(defaultSchema, {
87614
- protocols: ['doc', 'ref', 'blog', 'changelog', 'page'],
87614
+ attributes: {
87615
+ a: ['target'],
87616
+ },
87617
+ protocols: {
87618
+ href: ['doc', 'ref', 'blog', 'changelog', 'page'],
87619
+ },
87615
87620
  });
87616
87621
  const compile_compile = (text, { components = {}, missingComponents, copyButtons, useTailwind, ...opts } = {}) => {
87617
87622
  // Destructure at runtime to avoid circular dependency issues
@@ -97202,17 +97207,46 @@ function mdxComponent() {
97202
97207
 
97203
97208
 
97204
97209
 
97210
+
97211
+
97212
+
97213
+
97214
+ const buildInlineMdProcessor = (safeMode) => {
97215
+ const micromarkExts = [mdxComponent(), syntax_gemoji(), legacyVariable(), magicBlock()];
97216
+ const fromMarkdownExts = [
97217
+ mdxComponentFromMarkdown(),
97218
+ gemojiFromMarkdown(),
97219
+ legacyVariableFromMarkdown(),
97220
+ emptyTaskListItemFromMarkdown(),
97221
+ magicBlockFromMarkdown(),
97222
+ ];
97223
+ // Since evaluating expressions can be dangerous, do so only when safeMode is off
97224
+ if (!safeMode) {
97225
+ const mdxExprExt = mdxExpression({ allowEmpty: true });
97226
+ micromarkExts.push({ text: mdxExprExt.text });
97227
+ fromMarkdownExts.push(mdxExpressionFromMarkdown());
97228
+ }
97229
+ return unified()
97230
+ .data('micromarkExtensions', micromarkExts)
97231
+ .data('fromMarkdownExtensions', fromMarkdownExts)
97232
+ .use(remarkParse)
97233
+ .use(remarkGfm);
97234
+ };
97235
+ const processorCache = new Map();
97205
97236
  /**
97206
- * Shared unified processor for re-parsing the body of an MDX-ish component.
97207
- * Used by both the block and inline-block transformers so a nested component
97208
- * (e.g. `<Anchor>text with <b>bold</b></Anchor>`) goes through the same
97209
- * tokenizer chain as the top-level parse.
97237
+ * Unified processor for re-parsing the body of an MDX component
97238
+ * Memoized based on the argument value so we don't pay the construction cost on every parse
97239
+ * Currently the argument is only safeMode, but we could add more arguments in the future,
97240
+ * in which case the key would need to be extend to include the new arguments.
97210
97241
  */
97211
- const inlineMdProcessor = unified()
97212
- .data('micromarkExtensions', [mdxComponent(), legacyVariable(), magicBlock()])
97213
- .data('fromMarkdownExtensions', [mdxComponentFromMarkdown(), legacyVariableFromMarkdown(), emptyTaskListItemFromMarkdown(), magicBlockFromMarkdown()])
97214
- .use(remarkParse)
97215
- .use(remarkGfm);
97242
+ const getInlineMdProcessor = ({ safeMode = false } = {}) => {
97243
+ let processor = processorCache.get(safeMode);
97244
+ if (!processor) {
97245
+ processor = buildInlineMdProcessor(safeMode);
97246
+ processorCache.set(safeMode, processor);
97247
+ }
97248
+ return processor;
97249
+ };
97216
97250
  /**
97217
97251
  * True when a tag name starts with an uppercase letter — ReadMe's marker for
97218
97252
  * a custom MDX component (vs a lowercase HTML tag).
@@ -97253,11 +97287,11 @@ const toMdxJsxTextElement = (name, attributes, children, position) => ({
97253
97287
  * rejects line endings), so the paragraph-flatten path covers every case we
97254
97288
  * actually produce; other shapes fall back to empty children.
97255
97289
  */
97256
- const parsePhrasingChildren = (value) => {
97290
+ const parsePhrasingChildren = (value, safeMode) => {
97257
97291
  const trimmed = value.trim();
97258
97292
  if (!trimmed)
97259
97293
  return [];
97260
- const [first] = inlineMdProcessor.parse(trimmed).children;
97294
+ const [first] = getInlineMdProcessor({ safeMode }).parse(trimmed).children;
97261
97295
  return first?.type === 'paragraph' ? first.children : [];
97262
97296
  };
97263
97297
  /**
@@ -97270,7 +97304,7 @@ const parsePhrasingChildren = (value) => {
97270
97304
  *
97271
97305
  * Returns the original node unchanged when it doesn't qualify.
97272
97306
  */
97273
- const promoteInlineHtml = (node, parseOpts) => {
97307
+ const promoteInlineHtml = (node, parseOpts, safeMode) => {
97274
97308
  const parsed = parseTag((node.value ?? '').trim(), parseOpts);
97275
97309
  if (!parsed)
97276
97310
  return node;
@@ -97295,7 +97329,7 @@ const promoteInlineHtml = (node, parseOpts) => {
97295
97329
  if (closeIdx < 0)
97296
97330
  return node;
97297
97331
  const inner = contentAfterTag.slice(0, closeIdx);
97298
- return toMdxJsxTextElement(tag, attributes, parsePhrasingChildren(inner), node.position);
97332
+ return toMdxJsxTextElement(tag, attributes, parsePhrasingChildren(inner, safeMode), node.position);
97299
97333
  };
97300
97334
  /**
97301
97335
  * Transform inline html nodes with expression attributes
@@ -97314,9 +97348,10 @@ const promoteInlineHtml = (node, parseOpts) => {
97314
97348
  * `<a href="x">` stays as an html node for rehype-raw.
97315
97349
  */
97316
97350
  const mdxishInlineMdxHtmlBlocks = (opts = {}) => tree => {
97317
- const parseOpts = { preserveExpressionsAsText: !!opts.safeMode };
97351
+ const safeMode = !!opts.safeMode;
97352
+ const parseOpts = { preserveExpressionsAsText: safeMode };
97318
97353
  visit(tree, 'paragraph', (paragraph) => {
97319
- paragraph.children = paragraph.children.map(child => child.type === 'html' ? promoteInlineHtml(child, parseOpts) : child);
97354
+ paragraph.children = paragraph.children.map(child => child.type === 'html' ? promoteInlineHtml(child, parseOpts, safeMode) : child);
97320
97355
  });
97321
97356
  };
97322
97357
  /* harmony default export */ const inline_html = (mdxishInlineMdxHtmlBlocks);
@@ -97399,15 +97434,15 @@ function safeDeindent(text) {
97399
97434
  * Dedents the content first to prevent indented component content
97400
97435
  * (from nested components) from being treated as code blocks.
97401
97436
  */
97402
- const parseMdChildren = (value) => {
97403
- const parsed = inlineMdProcessor.parse(safeDeindent(value).trim());
97437
+ const parseMdChildren = (value, safeMode) => {
97438
+ const parsed = getInlineMdProcessor({ safeMode }).parse(safeDeindent(value).trim());
97404
97439
  return parsed.children || [];
97405
97440
  };
97406
97441
  /**
97407
97442
  * Parse substring content of a node and update the parent's children to include the new nodes.
97408
97443
  */
97409
- const parseSibling = (stack, parent, index, sibling) => {
97410
- const siblingNodes = parseMdChildren(sibling);
97444
+ const parseSibling = (stack, parent, index, sibling, safeMode) => {
97445
+ const siblingNodes = parseMdChildren(sibling, safeMode);
97411
97446
  // The new sibling nodes might contain new components to be processed
97412
97447
  if (siblingNodes.length > 0) {
97413
97448
  parent.children.splice(index + 1, 0, ...siblingNodes);
@@ -97459,7 +97494,8 @@ const substituteNodeWithMdxNode = (parent, index, mdxNode) => {
97459
97494
  */
97460
97495
  const mdxishMdxComponentBlocks = (opts = {}) => tree => {
97461
97496
  const stack = [tree];
97462
- const parseOpts = { preserveExpressionsAsText: !!opts.safeMode };
97497
+ const safeMode = !!opts.safeMode;
97498
+ const parseOpts = { preserveExpressionsAsText: safeMode };
97463
97499
  const processChildNode = (parent, index) => {
97464
97500
  const node = parent.children[index];
97465
97501
  if (!node)
@@ -97505,7 +97541,7 @@ const mdxishMdxComponentBlocks = (opts = {}) => tree => {
97505
97541
  // Check and parse if there's relevant content after the current closing tag
97506
97542
  const remainingContent = contentAfterTag.trim();
97507
97543
  if (remainingContent) {
97508
- parseSibling(stack, parent, index, remainingContent);
97544
+ parseSibling(stack, parent, index, remainingContent, safeMode);
97509
97545
  }
97510
97546
  return;
97511
97547
  }
@@ -97518,7 +97554,7 @@ const mdxishMdxComponentBlocks = (opts = {}) => tree => {
97518
97554
  const componentInnerContent = contentAfterTag.substring(0, closingTagIndex);
97519
97555
  const contentAfterClose = contentAfterTag.substring(closingTagIndex + closingTagStr.length).trim();
97520
97556
  let parsedChildren = componentInnerContent.trim()
97521
- ? parseMdChildren(componentInnerContent)
97557
+ ? parseMdChildren(componentInnerContent, safeMode)
97522
97558
  : [];
97523
97559
  // Lowercase HTML tags are usually inline (e.g. <a>, <span>). Remark wraps
97524
97560
  // bare text in a paragraph; unwrap when there's exactly one paragraph so
@@ -97535,7 +97571,7 @@ const mdxishMdxComponentBlocks = (opts = {}) => tree => {
97535
97571
  substituteNodeWithMdxNode(parent, index, componentNode);
97536
97572
  // After the closing tag, there might be more content to be processed
97537
97573
  if (contentAfterClose) {
97538
- parseSibling(stack, parent, index, contentAfterClose);
97574
+ parseSibling(stack, parent, index, contentAfterClose, safeMode);
97539
97575
  }
97540
97576
  else if (componentNode.children.length > 0) {
97541
97577
  // The content inside the component block might contain new components to be processed
@@ -101853,15 +101889,18 @@ function mdxishAstProcessor(mdContent, opts = {}) {
101853
101889
  .use(remarkParse)
101854
101890
  .use(remarkFrontmatter)
101855
101891
  .use(normalize_malformed_md_syntax)
101856
- .use(magic_block_transformer)
101857
- .use(transform_images, { isMdxish: true })
101858
- .use(defaultTransformers)
101859
101892
  .use(self_closing_blocks)
101860
101893
  .use(mdx_blocks, { safeMode })
101861
101894
  .use(inline_html, { safeMode })
101862
101895
  .use(restore_snake_case_component_name, { mapping: snakeCaseMapping })
101863
101896
  .use(mdxish_tables)
101864
101897
  .use(mdxish_html_blocks)
101898
+ // The next few transformers must appear after mdxishMdxComponentBlocks
101899
+ // so nodes produced by the inline re-parse of component bodies
101900
+ // (e.g. code/image/embed inside <Tabs>) get visited too
101901
+ .use(magic_block_transformer)
101902
+ .use(transform_images, { isMdxish: true })
101903
+ .use(defaultTransformers)
101865
101904
  .use(newEditorTypes ? inline_mdx_blocks : undefined) // Merge inline html components (e.g. <Anchor>) into MDAST nodes
101866
101905
  .use(newEditorTypes ? mdxish_jsx_to_mdast : undefined) // Convert block JSX elements to MDAST types
101867
101906
  .use(variables_text) // Parse {user.*} patterns from text nodes
package/dist/main.node.js CHANGED
@@ -107805,7 +107805,12 @@ const tocHastToMdx = (toc, components, variables) => {
107805
107805
 
107806
107806
 
107807
107807
  const sanitizeSchema = cjs_default()(defaultSchema, {
107808
- protocols: ['doc', 'ref', 'blog', 'changelog', 'page'],
107808
+ attributes: {
107809
+ a: ['target'],
107810
+ },
107811
+ protocols: {
107812
+ href: ['doc', 'ref', 'blog', 'changelog', 'page'],
107813
+ },
107809
107814
  });
107810
107815
  const compile_compile = (text, { components = {}, missingComponents, copyButtons, useTailwind, ...opts } = {}) => {
107811
107816
  // Destructure at runtime to avoid circular dependency issues
@@ -117396,17 +117401,46 @@ function mdxComponent() {
117396
117401
 
117397
117402
 
117398
117403
 
117404
+
117405
+
117406
+
117407
+
117408
+ const buildInlineMdProcessor = (safeMode) => {
117409
+ const micromarkExts = [mdxComponent(), syntax_gemoji(), legacyVariable(), magicBlock()];
117410
+ const fromMarkdownExts = [
117411
+ mdxComponentFromMarkdown(),
117412
+ gemojiFromMarkdown(),
117413
+ legacyVariableFromMarkdown(),
117414
+ emptyTaskListItemFromMarkdown(),
117415
+ magicBlockFromMarkdown(),
117416
+ ];
117417
+ // Since evaluating expressions can be dangerous, do so only when safeMode is off
117418
+ if (!safeMode) {
117419
+ const mdxExprExt = mdxExpression({ allowEmpty: true });
117420
+ micromarkExts.push({ text: mdxExprExt.text });
117421
+ fromMarkdownExts.push(mdxExpressionFromMarkdown());
117422
+ }
117423
+ return unified()
117424
+ .data('micromarkExtensions', micromarkExts)
117425
+ .data('fromMarkdownExtensions', fromMarkdownExts)
117426
+ .use(remarkParse)
117427
+ .use(remarkGfm);
117428
+ };
117429
+ const processorCache = new Map();
117399
117430
  /**
117400
- * Shared unified processor for re-parsing the body of an MDX-ish component.
117401
- * Used by both the block and inline-block transformers so a nested component
117402
- * (e.g. `<Anchor>text with <b>bold</b></Anchor>`) goes through the same
117403
- * tokenizer chain as the top-level parse.
117431
+ * Unified processor for re-parsing the body of an MDX component
117432
+ * Memoized based on the argument value so we don't pay the construction cost on every parse
117433
+ * Currently the argument is only safeMode, but we could add more arguments in the future,
117434
+ * in which case the key would need to be extend to include the new arguments.
117404
117435
  */
117405
- const inlineMdProcessor = unified()
117406
- .data('micromarkExtensions', [mdxComponent(), legacyVariable(), magicBlock()])
117407
- .data('fromMarkdownExtensions', [mdxComponentFromMarkdown(), legacyVariableFromMarkdown(), emptyTaskListItemFromMarkdown(), magicBlockFromMarkdown()])
117408
- .use(remarkParse)
117409
- .use(remarkGfm);
117436
+ const getInlineMdProcessor = ({ safeMode = false } = {}) => {
117437
+ let processor = processorCache.get(safeMode);
117438
+ if (!processor) {
117439
+ processor = buildInlineMdProcessor(safeMode);
117440
+ processorCache.set(safeMode, processor);
117441
+ }
117442
+ return processor;
117443
+ };
117410
117444
  /**
117411
117445
  * True when a tag name starts with an uppercase letter — ReadMe's marker for
117412
117446
  * a custom MDX component (vs a lowercase HTML tag).
@@ -117447,11 +117481,11 @@ const toMdxJsxTextElement = (name, attributes, children, position) => ({
117447
117481
  * rejects line endings), so the paragraph-flatten path covers every case we
117448
117482
  * actually produce; other shapes fall back to empty children.
117449
117483
  */
117450
- const parsePhrasingChildren = (value) => {
117484
+ const parsePhrasingChildren = (value, safeMode) => {
117451
117485
  const trimmed = value.trim();
117452
117486
  if (!trimmed)
117453
117487
  return [];
117454
- const [first] = inlineMdProcessor.parse(trimmed).children;
117488
+ const [first] = getInlineMdProcessor({ safeMode }).parse(trimmed).children;
117455
117489
  return first?.type === 'paragraph' ? first.children : [];
117456
117490
  };
117457
117491
  /**
@@ -117464,7 +117498,7 @@ const parsePhrasingChildren = (value) => {
117464
117498
  *
117465
117499
  * Returns the original node unchanged when it doesn't qualify.
117466
117500
  */
117467
- const promoteInlineHtml = (node, parseOpts) => {
117501
+ const promoteInlineHtml = (node, parseOpts, safeMode) => {
117468
117502
  const parsed = parseTag((node.value ?? '').trim(), parseOpts);
117469
117503
  if (!parsed)
117470
117504
  return node;
@@ -117489,7 +117523,7 @@ const promoteInlineHtml = (node, parseOpts) => {
117489
117523
  if (closeIdx < 0)
117490
117524
  return node;
117491
117525
  const inner = contentAfterTag.slice(0, closeIdx);
117492
- return toMdxJsxTextElement(tag, attributes, parsePhrasingChildren(inner), node.position);
117526
+ return toMdxJsxTextElement(tag, attributes, parsePhrasingChildren(inner, safeMode), node.position);
117493
117527
  };
117494
117528
  /**
117495
117529
  * Transform inline html nodes with expression attributes
@@ -117508,9 +117542,10 @@ const promoteInlineHtml = (node, parseOpts) => {
117508
117542
  * `<a href="x">` stays as an html node for rehype-raw.
117509
117543
  */
117510
117544
  const mdxishInlineMdxHtmlBlocks = (opts = {}) => tree => {
117511
- const parseOpts = { preserveExpressionsAsText: !!opts.safeMode };
117545
+ const safeMode = !!opts.safeMode;
117546
+ const parseOpts = { preserveExpressionsAsText: safeMode };
117512
117547
  visit(tree, 'paragraph', (paragraph) => {
117513
- paragraph.children = paragraph.children.map(child => child.type === 'html' ? promoteInlineHtml(child, parseOpts) : child);
117548
+ paragraph.children = paragraph.children.map(child => child.type === 'html' ? promoteInlineHtml(child, parseOpts, safeMode) : child);
117514
117549
  });
117515
117550
  };
117516
117551
  /* harmony default export */ const inline_html = (mdxishInlineMdxHtmlBlocks);
@@ -117593,15 +117628,15 @@ function safeDeindent(text) {
117593
117628
  * Dedents the content first to prevent indented component content
117594
117629
  * (from nested components) from being treated as code blocks.
117595
117630
  */
117596
- const parseMdChildren = (value) => {
117597
- const parsed = inlineMdProcessor.parse(safeDeindent(value).trim());
117631
+ const parseMdChildren = (value, safeMode) => {
117632
+ const parsed = getInlineMdProcessor({ safeMode }).parse(safeDeindent(value).trim());
117598
117633
  return parsed.children || [];
117599
117634
  };
117600
117635
  /**
117601
117636
  * Parse substring content of a node and update the parent's children to include the new nodes.
117602
117637
  */
117603
- const parseSibling = (stack, parent, index, sibling) => {
117604
- const siblingNodes = parseMdChildren(sibling);
117638
+ const parseSibling = (stack, parent, index, sibling, safeMode) => {
117639
+ const siblingNodes = parseMdChildren(sibling, safeMode);
117605
117640
  // The new sibling nodes might contain new components to be processed
117606
117641
  if (siblingNodes.length > 0) {
117607
117642
  parent.children.splice(index + 1, 0, ...siblingNodes);
@@ -117653,7 +117688,8 @@ const substituteNodeWithMdxNode = (parent, index, mdxNode) => {
117653
117688
  */
117654
117689
  const mdxishMdxComponentBlocks = (opts = {}) => tree => {
117655
117690
  const stack = [tree];
117656
- const parseOpts = { preserveExpressionsAsText: !!opts.safeMode };
117691
+ const safeMode = !!opts.safeMode;
117692
+ const parseOpts = { preserveExpressionsAsText: safeMode };
117657
117693
  const processChildNode = (parent, index) => {
117658
117694
  const node = parent.children[index];
117659
117695
  if (!node)
@@ -117699,7 +117735,7 @@ const mdxishMdxComponentBlocks = (opts = {}) => tree => {
117699
117735
  // Check and parse if there's relevant content after the current closing tag
117700
117736
  const remainingContent = contentAfterTag.trim();
117701
117737
  if (remainingContent) {
117702
- parseSibling(stack, parent, index, remainingContent);
117738
+ parseSibling(stack, parent, index, remainingContent, safeMode);
117703
117739
  }
117704
117740
  return;
117705
117741
  }
@@ -117712,7 +117748,7 @@ const mdxishMdxComponentBlocks = (opts = {}) => tree => {
117712
117748
  const componentInnerContent = contentAfterTag.substring(0, closingTagIndex);
117713
117749
  const contentAfterClose = contentAfterTag.substring(closingTagIndex + closingTagStr.length).trim();
117714
117750
  let parsedChildren = componentInnerContent.trim()
117715
- ? parseMdChildren(componentInnerContent)
117751
+ ? parseMdChildren(componentInnerContent, safeMode)
117716
117752
  : [];
117717
117753
  // Lowercase HTML tags are usually inline (e.g. <a>, <span>). Remark wraps
117718
117754
  // bare text in a paragraph; unwrap when there's exactly one paragraph so
@@ -117729,7 +117765,7 @@ const mdxishMdxComponentBlocks = (opts = {}) => tree => {
117729
117765
  substituteNodeWithMdxNode(parent, index, componentNode);
117730
117766
  // After the closing tag, there might be more content to be processed
117731
117767
  if (contentAfterClose) {
117732
- parseSibling(stack, parent, index, contentAfterClose);
117768
+ parseSibling(stack, parent, index, contentAfterClose, safeMode);
117733
117769
  }
117734
117770
  else if (componentNode.children.length > 0) {
117735
117771
  // The content inside the component block might contain new components to be processed
@@ -122047,15 +122083,18 @@ function mdxishAstProcessor(mdContent, opts = {}) {
122047
122083
  .use(remarkParse)
122048
122084
  .use(remarkFrontmatter)
122049
122085
  .use(normalize_malformed_md_syntax)
122050
- .use(magic_block_transformer)
122051
- .use(transform_images, { isMdxish: true })
122052
- .use(defaultTransformers)
122053
122086
  .use(self_closing_blocks)
122054
122087
  .use(mdx_blocks, { safeMode })
122055
122088
  .use(inline_html, { safeMode })
122056
122089
  .use(restore_snake_case_component_name, { mapping: snakeCaseMapping })
122057
122090
  .use(mdxish_tables)
122058
122091
  .use(mdxish_html_blocks)
122092
+ // The next few transformers must appear after mdxishMdxComponentBlocks
122093
+ // so nodes produced by the inline re-parse of component bodies
122094
+ // (e.g. code/image/embed inside <Tabs>) get visited too
122095
+ .use(magic_block_transformer)
122096
+ .use(transform_images, { isMdxish: true })
122097
+ .use(defaultTransformers)
122059
122098
  .use(newEditorTypes ? inline_mdx_blocks : undefined) // Merge inline html components (e.g. <Anchor>) into MDAST nodes
122060
122099
  .use(newEditorTypes ? mdxish_jsx_to_mdast : undefined) // Convert block JSX elements to MDAST types
122061
122100
  .use(variables_text) // Parse {user.*} patterns from text nodes