@readme/markdown 15.2.0 → 15.3.0

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,8 @@
1
+ import type { Transform } from 'mdast-util-from-markdown';
2
+ /**
3
+ * Serializes mdxish anchors to JSX `<Anchor>` syntax. Handing the node to
4
+ * `mdast-util-mdx-jsx` runs the label through the document's own serializer
5
+ * state, so readme nodes (variables, emoji, glossary) reach their handlers.
6
+ */
7
+ declare const mdxishAnchorToJsx: () => Transform;
8
+ export default mdxishAnchorToJsx;
@@ -2,8 +2,11 @@
2
2
  export declare const HTML_TAG_RE: RegExp;
3
3
  /** Matches an HTML element from its opening tag to the matching closing tag. */
4
4
  export declare const HTML_ELEMENT_BLOCK_RE: RegExp;
5
+ export declare const NEWLINE_RE: RegExp;
5
6
  /** Matches a newline with surrounding horizontal whitespace. */
6
7
  export declare const NEWLINE_WITH_WHITESPACE_RE: RegExp;
8
+ /** Matches a run of two or more newlines (a blank line) with surrounding horizontal whitespace. */
9
+ export declare const BLANK_LINE_RE: RegExp;
7
10
  /** Matches a closing block-level tag followed by non-tag text or by a newline then non-blank content. */
8
11
  export declare const CLOSE_BLOCK_TAG_BOUNDARY_RE: RegExp;
9
12
  /** Strips HTML open/close tags. Used to detect non-tag inner text content. */
@@ -63,6 +63,7 @@ export interface RecipeJson extends MagicBlockJson {
63
63
  }
64
64
  export interface MagicBlockTransformerOptions {
65
65
  compatibilityMode?: boolean;
66
+ hardBreaks?: boolean;
66
67
  safeMode?: boolean;
67
68
  }
68
69
  /**
@@ -19045,7 +19045,7 @@ module.exports = function () {
19045
19045
 
19046
19046
  /***/ },
19047
19047
 
19048
- /***/ 6009
19048
+ /***/ 345
19049
19049
  (module, __webpack_exports__, __webpack_require__) {
19050
19050
 
19051
19051
  "use strict";
@@ -95928,6 +95928,7 @@ var allCSS2RNProps = __webpack_unused_export__ = flatten([allProps, CSS2RNProps]
95928
95928
 
95929
95929
 
95930
95930
 
95931
+
95931
95932
  /**
95932
95933
  * Extract word boundaries from camelCase strings (e.g., "borderWidth" -> ["border", "width"])
95933
95934
  */
@@ -96007,10 +96008,43 @@ const CUSTOM_PROP_BOUNDARIES = [
96007
96008
  */
96008
96009
  const RUNTIME_COMPONENT_TAGS = new Set(['Variable', 'variable', 'html-block', 'rdme-pin']);
96009
96010
  /**
96010
- * Standard HTML tags that should never be treated as custom components.
96011
- * Uses the html-tags package, converted to a Set<string> for efficient lookups.
96011
+ * Elements that are not actually standard HTML tags, or those that we intentionally
96012
+ * don't want to treat as one & is mute to check with. These include:
96013
+ * - SVG/MathML descendants
96014
+ * - Namespaced foreign content
96015
+ * - `image`, which the HTML tree builder rewrites to `img`
96016
+ * Most of these are bundled in parse5's `TAG_NAMES` set, but we can also add a few more.
96017
+ */
96018
+ const NON_STANDARD_TAGS = new Set([
96019
+ 'annotation-xml',
96020
+ 'desc',
96021
+ 'foreignObject',
96022
+ 'image',
96023
+ 'malignmark',
96024
+ 'mglyph',
96025
+ 'mi',
96026
+ 'mn',
96027
+ 'mo',
96028
+ 'ms',
96029
+ 'mtext',
96030
+ ]);
96031
+ /**
96032
+ * Standard HTML tags list.
96033
+ * A use case of this is to differentiate custom components tag vs standard HTML tags.
96034
+ *
96035
+ * Unioned from:
96036
+ * - `html-tags`: All modern spec HTML elements
96037
+ * - parse5's `TAG_NAMES`: Elements the HTML tree-construction algorithm has to special-case
96038
+ * This includes obsolete tags that are still rendered by browsers.
96039
+ * - NON_STANDARD_TAGS: We've had to filter because currently parse5's `TAG_NAMES` set over-enumerates
96040
+ * tags that are not actually standard HTML tags. It also allows custom tags to be filtered out.
96012
96041
  */
96013
- const STANDARD_HTML_TAGS = new Set(html_tags_namespaceObject);
96042
+ const STANDARD_HTML_TAGS = new Set([
96043
+ ...html_tags_namespaceObject,
96044
+ ...Object.values(TAG_NAMES),
96045
+ 'acronym', // Obselete tag not included either of the above sources. Add here if we have missed any.
96046
+ 'blink',
96047
+ ].filter(tag => !NON_STANDARD_TAGS.has(tag)));
96014
96048
  /**
96015
96049
  * Table structural tags. Blank lines inside these carry deliberate meaning for
96016
96050
  * `mdxishTables` (e.g. splitting cell content into paragraphs, or deciding
@@ -121415,27 +121449,6 @@ function htmlToMarkdown(html) {
121415
121449
  return processor.processSync(html).toString().trim();
121416
121450
  }
121417
121451
 
121418
- ;// ./processor/compile/anchor.ts
121419
-
121420
-
121421
- const anchor_anchor = (node) => {
121422
- const { href, label, target, title } = getHProps(node);
121423
- const attrs = {
121424
- ...(label && { label }),
121425
- ...(target && { target }),
121426
- href: href ?? '',
121427
- ...(title && { title }),
121428
- };
121429
- // Serialize children (phrasing content) back to markdown
121430
- // Wrap in paragraph to satisfy RootContent type requirement
121431
- const children = toMarkdown({
121432
- type: 'paragraph',
121433
- children: node.children,
121434
- }).trim();
121435
- return `<Anchor ${formatProps(attrs)}>${children}</Anchor>`;
121436
- };
121437
- /* harmony default export */ const compile_anchor = (anchor_anchor);
121438
-
121439
121452
  ;// ./processor/compile/callout.ts
121440
121453
 
121441
121454
  const callout = (node, _, state, info) => {
@@ -121593,7 +121606,6 @@ const compile_text_text = (node, parent, state, info) => {
121593
121606
 
121594
121607
 
121595
121608
 
121596
-
121597
121609
  function compilers(mdxish = false) {
121598
121610
  const data = this.data();
121599
121611
  const toMarkdownExtensions = data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
@@ -121613,7 +121625,6 @@ function compilers(mdxish = false) {
121613
121625
  plain: compile_plain,
121614
121626
  yaml: compile_compatibility,
121615
121627
  // needed only for mdxish
121616
- ...(mdxish && { [NodeTypes.anchor]: compile_anchor }),
121617
121628
  ...(mdxish && { list: compile_list }),
121618
121629
  ...(mdxish && { listItem: list_item }),
121619
121630
  ...(mdxish && { text: compile_text }),
@@ -122078,6 +122089,43 @@ const mdxComponentHandlers = {
122078
122089
  [NodeTypes.htmlBlock]: htmlBlockHandler,
122079
122090
  };
122080
122091
 
122092
+ ;// ./processor/transform/mdxish/anchor-to-jsx.ts
122093
+ /* unused harmony import specifier */ var anchor_to_jsx_visit;
122094
+ /* unused harmony import specifier */ var anchor_to_jsx_NodeTypes;
122095
+ /* unused harmony import specifier */ var anchor_to_jsx_getHProps;
122096
+ /* unused harmony import specifier */ var anchor_to_jsx_toAttributes;
122097
+
122098
+
122099
+
122100
+ /**
122101
+ * Serializes mdxish anchors to JSX `<Anchor>` syntax. Handing the node to
122102
+ * `mdast-util-mdx-jsx` runs the label through the document's own serializer
122103
+ * state, so readme nodes (variables, emoji, glossary) reach their handlers.
122104
+ */
122105
+ const mdxishAnchorToJsx = () => tree => {
122106
+ anchor_to_jsx_visit(tree, anchor_to_jsx_NodeTypes.anchor, (node, index, parent) => {
122107
+ if (!parent || index === undefined)
122108
+ return;
122109
+ const { href, label, target, title } = anchor_to_jsx_getHProps(node);
122110
+ const jsx = {
122111
+ type: 'mdxJsxTextElement',
122112
+ name: 'Anchor',
122113
+ // An anchor always renders an `href`, even an empty one, so it's built
122114
+ // directly rather than through `toAttributes`, which drops empty values.
122115
+ attributes: [
122116
+ ...anchor_to_jsx_toAttributes({ label, target }),
122117
+ { type: 'mdxJsxAttribute', name: 'href', value: href ?? '' },
122118
+ ...anchor_to_jsx_toAttributes({ title }),
122119
+ ],
122120
+ children: node.children,
122121
+ position: node.position,
122122
+ };
122123
+ parent.children[index] = jsx;
122124
+ });
122125
+ return tree;
122126
+ };
122127
+ /* harmony default export */ const anchor_to_jsx = ((/* unused pure expression or super */ null && (mdxishAnchorToJsx)));
122128
+
122081
122129
  ;// ./processor/transform/mdxish/callout-to-jsx.ts
122082
122130
  /* unused harmony import specifier */ var callout_to_jsx_visit;
122083
122131
  /* unused harmony import specifier */ var callout_to_jsx_defaultIcons;
@@ -125284,8 +125332,11 @@ function rehypeStringify(options) {
125284
125332
  const HTML_TAG_RE = /<\/?([a-zA-Z][a-zA-Z0-9-]*)((?:[^>"']*(?:"[^"]*"|'[^']*'))*[^>"']*)>/g;
125285
125333
  /** Matches an HTML element from its opening tag to the matching closing tag. */
125286
125334
  const HTML_ELEMENT_BLOCK_RE = /<([a-zA-Z][a-zA-Z0-9-]*)[\s>][\s\S]*?<\/\1>/g;
125335
+ const NEWLINE_RE = /\n/g;
125287
125336
  /** Matches a newline with surrounding horizontal whitespace. */
125288
125337
  const NEWLINE_WITH_WHITESPACE_RE = /[^\S\n]*\n[^\S\n]*/g;
125338
+ /** Matches a run of two or more newlines (a blank line) with surrounding horizontal whitespace. */
125339
+ const BLANK_LINE_RE = /[^\S\n]*\n(?:[^\S\n]*\n)+[^\S\n]*/g;
125289
125340
  /** Matches a closing block-level tag followed by non-tag text or by a newline then non-blank content. */
125290
125341
  const CLOSE_BLOCK_TAG_BOUNDARY_RE = /<\/([a-zA-Z][a-zA-Z0-9-]*)>\s*(?:(?!<)(\S)|\n([^\n]))/g;
125291
125342
  /** Strips HTML open/close tags. Used to detect non-tag inner text content. */
@@ -125355,7 +125406,6 @@ const EMPTY_CODE_PLACEHOLDER = {
125355
125406
 
125356
125407
 
125357
125408
 
125358
-
125359
125409
  /**
125360
125410
  * Wraps a node in a "pinned" container if sidebar: true is set.
125361
125411
  */
@@ -125390,16 +125440,13 @@ const textToBlock = (text) => [{ children: textToInline(text), type: 'paragraph'
125390
125440
  */
125391
125441
  const ensureLeadingBreaks = (text) => text.replace(/^\n+/, match => '<br>'.repeat(match.length));
125392
125442
  /** Preprocesses magic block body content before parsing. */
125393
- const preprocessBody = (text) => {
125394
- return ensureLeadingBreaks(text);
125395
- };
125443
+ const preprocessBody = (text, hardBreaks) => (hardBreaks ? ensureLeadingBreaks(text) : text);
125396
125444
  const bodyExtensions = mdxishExtensions(FEATURES.magicBlockBody);
125397
125445
  /** Markdown parser */
125398
125446
  const contentParser = unified()
125399
125447
  .data('micromarkExtensions', bodyExtensions.micromarkExtensions)
125400
125448
  .data('fromMarkdownExtensions', bodyExtensions.fromMarkdownExtensions)
125401
125449
  .use(remarkParse)
125402
- .use(hard_breaks)
125403
125450
  .use(remarkGfm)
125404
125451
  .use(normalize_malformed_md_syntax);
125405
125452
  /**
@@ -125496,17 +125543,21 @@ const processMarkdownInHtmlString = (html) => {
125496
125543
  /**
125497
125544
  * Separate a closing block-level tag from the content that follows it.
125498
125545
  *
125499
- * Each \n in the original text becomes a <br> tag to preserve spacing, then a
125500
- * blank line (\n\n) is appended so CommonMark ends the HTML block and parses
125501
- * the following content as markdown.
125546
+ * A blank line (\n\n) is appended so CommonMark ends the HTML block and parses the
125547
+ * following content as markdown; with hard breaks each \n also becomes a <br> to keep its spacing.
125502
125548
  */
125503
- const separateBlockTagFromContent = (match, tag, inlineChar, nextLineChar) => {
125549
+ const separateBlockTagFromContent = (hardBreaks, match, tag, inlineChar, nextLineChar) => {
125504
125550
  if (!BLOCK_LEVEL_TAGS.has(tag.toLowerCase()))
125505
125551
  return match;
125506
- const newlineCount = (match.match(/\n/g) ?? []).length;
125552
+ const newlineCount = hardBreaks ? (match.match(NEWLINE_RE) ?? []).length : 0;
125507
125553
  const breaks = '<br>'.repeat(newlineCount);
125508
125554
  return `</${tag}>${breaks}\n\n${inlineChar || nextLineChar}`;
125509
125555
  };
125556
+ /**
125557
+ * Newlines inside an HTML block become <br> so CommonMark doesn't end the block on a blank
125558
+ * line. Without hard breaks only blank lines break, but they still have to be replaced.
125559
+ */
125560
+ const collapseHtmlBlockNewlines = (html, hardBreaks) => html.replace(hardBreaks ? NEWLINE_WITH_WHITESPACE_RE : BLANK_LINE_RE, '<br>');
125510
125561
  /** Escape a leading (possibly indented) `-`/`*`/`+` so cells don't become bullet lists. */
125511
125562
  const escapeLeadingListMarkers = (text) => text.replace(/^([ \t]*)([-*+])(?=[ \t]|$)/gm, '$1\\$2');
125512
125563
  /**
@@ -125514,15 +125565,13 @@ const escapeLeadingListMarkers = (text) => text.replace(/^([ \t]*)([-*+])(?=[ \t
125514
125565
  * so `<ul><li>_text_</li></ul>` won't convert underscores to emphasis.
125515
125566
  * We parse first, then visit html nodes and process their text content.
125516
125567
  */
125517
- const parseTableCell = (text) => {
125568
+ const parseTableCell = (text, hardBreaks) => {
125518
125569
  if (!text.trim())
125519
125570
  return [{ type: 'text', value: '' }];
125520
- // Convert \n (and surrounding whitespace) to <br> inside HTML blocks so
125521
- // CommonMark doesn't split them on blank lines.
125522
125571
  const escaped = processBackslashEscapes(text);
125523
125572
  const normalized = escaped
125524
- .replace(HTML_ELEMENT_BLOCK_RE, match => match.replace(NEWLINE_WITH_WHITESPACE_RE, '<br>'))
125525
- .replace(CLOSE_BLOCK_TAG_BOUNDARY_RE, separateBlockTagFromContent);
125573
+ .replace(HTML_ELEMENT_BLOCK_RE, match => collapseHtmlBlockNewlines(match, hardBreaks))
125574
+ .replace(CLOSE_BLOCK_TAG_BOUNDARY_RE, (match, tag, inlineChar, nextLineChar) => separateBlockTagFromContent(hardBreaks, match, tag, inlineChar, nextLineChar));
125526
125575
  const processed = escapeLeadingListMarkers(normalized);
125527
125576
  const tree = contentParser.runSync(contentParser.parse(processed));
125528
125577
  // Process markdown inside HTML blocks that have non-tag inner text (e.g. `<div>**x**`
@@ -125571,7 +125620,7 @@ const parseApiHeaderTitle = (text) => {
125571
125620
  * Transform a magicBlock node into final MDAST nodes.
125572
125621
  */
125573
125622
  function transformMagicBlock(blockType, data, rawValue, options = {}) {
125574
- const { compatibilityMode = false, safeMode = false } = options;
125623
+ const { compatibilityMode = false, hardBreaks = true, safeMode = false } = options;
125575
125624
  // Handle empty data by returning placeholder nodes for known block types
125576
125625
  // This allows the editor to show appropriate placeholder UI instead of nothing
125577
125626
  if (Object.keys(data).length < 1) {
@@ -125710,7 +125759,7 @@ function transformMagicBlock(blockType, data, rawValue, options = {}) {
125710
125759
  });
125711
125760
  }
125712
125761
  if (hasBody) {
125713
- const bodyBlocks = parseBlock(preprocessBody(calloutJson.body || ''));
125762
+ const bodyBlocks = parseBlock(preprocessBody(calloutJson.body || '', hardBreaks));
125714
125763
  children.push(...bodyBlocks);
125715
125764
  }
125716
125765
  const calloutElement = {
@@ -125742,12 +125791,12 @@ function transformMagicBlock(blockType, data, rawValue, options = {}) {
125742
125791
  mapped[rowIndex][colIndex] = v;
125743
125792
  return mapped;
125744
125793
  }, []);
125745
- const tokenizeCell = compatibilityMode
125746
- ? textToBlock
125747
- : parseTableCell;
125794
+ const tokenizeCell = compatibilityMode ? textToBlock : (text) => parseTableCell(text, hardBreaks);
125748
125795
  const tableChildren = Array.from({ length: rows + 1 }, (_, y) => ({
125749
125796
  children: Array.from({ length: cols }, (__, x) => ({
125750
- children: sparseData[y]?.[x] ? tokenizeCell(preprocessBody(sparseData[y][x])) : [{ type: 'text', value: '' }],
125797
+ children: sparseData[y]?.[x]
125798
+ ? tokenizeCell(preprocessBody(sparseData[y][x], hardBreaks))
125799
+ : [{ type: 'text', value: '' }],
125751
125800
  type: y === 0 ? 'tableHead' : 'tableCell',
125752
125801
  })),
125753
125802
  type: 'tableRow',
@@ -127510,6 +127559,7 @@ function loadComponents() {
127510
127559
  /* unused harmony import specifier */ var mdxish_unified;
127511
127560
  /* unused harmony import specifier */ var mdxish_mdxishCompilers;
127512
127561
  /* unused harmony import specifier */ var mdxish_DEFAULT_BULLET;
127562
+ /* unused harmony import specifier */ var mdxish_mdxishAnchorToJsx;
127513
127563
  /* unused harmony import specifier */ var mdxish_mdxishCalloutToJsx;
127514
127564
  /* unused harmony import specifier */ var mdxish_mdxishTablesToJsx;
127515
127565
 
@@ -127564,6 +127614,7 @@ function loadComponents() {
127564
127614
 
127565
127615
 
127566
127616
 
127617
+
127567
127618
 
127568
127619
 
127569
127620
  const defaultTransformers = [
@@ -127602,7 +127653,7 @@ function preprocessContent(content, opts) {
127602
127653
  return processSnakeCaseComponent(result, { knownComponents });
127603
127654
  }
127604
127655
  function mdxishAstProcessor(mdContent, opts = {}) {
127605
- const { components: userComponents = {}, newEditorTypes = false, safeMode = false, useTailwind } = opts;
127656
+ const { components: userComponents = {}, hardBreaks: enableHardBreaks = true, newEditorTypes = false, safeMode = false, useTailwind, } = opts;
127606
127657
  const components = {
127607
127658
  ...loadComponents(),
127608
127659
  ...userComponents,
@@ -127631,7 +127682,7 @@ function mdxishAstProcessor(mdContent, opts = {}) {
127631
127682
  // The next few transformers must appear after mdxishMdxComponentBlocks
127632
127683
  // so nodes produced by the inline re-parse of component bodies
127633
127684
  // (e.g. code/image/embed inside <Tabs>) get visited too
127634
- .use(magic_block_transformer)
127685
+ .use(magic_block_transformer, { hardBreaks: enableHardBreaks })
127635
127686
  .use(transform_images, { isMdxish: true })
127636
127687
  .use(defaultTransformers)
127637
127688
  .use(newEditorTypes ? inline_mdx_blocks : undefined) // Merge inline html components (e.g. <Anchor>) into MDAST nodes
@@ -127666,6 +127717,7 @@ function mdxishMdastToMd(mdast) {
127666
127717
  .use(mdxish_remarkGfm)
127667
127718
  .use(mdxish_mdxishCalloutToJsx)
127668
127719
  .use(mdxish_mdxishTablesToJsx)
127720
+ .use(mdxish_mdxishAnchorToJsx)
127669
127721
  .use(mdxish_mdxishCompilers)
127670
127722
  .use(mdxJsxStringify)
127671
127723
  .use(mdxish_remarkStringify, {
@@ -127687,7 +127739,7 @@ function mdxishMdastToMd(mdast) {
127687
127739
  * @see .claude/context/MDXish/Processor Overview.md
127688
127740
  */
127689
127741
  function mdxish(mdContent, opts = {}) {
127690
- const { components: userComponents = {}, safeMode = false, variables } = opts;
127742
+ const { components: userComponents = {}, hardBreaks: enableHardBreaks = true, safeMode = false, variables } = opts;
127691
127743
  const components = {
127692
127744
  ...loadComponents(),
127693
127745
  ...userComponents,
@@ -127699,7 +127751,7 @@ function mdxish(mdContent, opts = {}) {
127699
127751
  const { processor, parserReadyContent } = mdxishAstProcessor(contentWithoutComments, opts);
127700
127752
  processor
127701
127753
  .use(safeMode ? undefined : evaluate_exports) // Evaluate `export const/function` and stash scope on file.data.mdxishScope
127702
- .use(hard_breaks) // Must precede evaluateExpressions to avoid splitting the \n in an evaluated template literal into a <br> node
127754
+ .use(enableHardBreaks ? hard_breaks : undefined) // Must precede evaluateExpressions to avoid splitting the \n in an evaluated template literal into a <br> node
127703
127755
  .use(safeMode ? undefined : evaluate_expressions) // Evaluate self-contained MDX expressions (e.g. `{1+1}`)
127704
127756
  .use(safeMode ? undefined : evaluate_style_block_expressions) // Evaluate `<style>{`...`}</style>` template literals into plain CSS
127705
127757
  .use(variables_code, { variables }) // Resolve <<...>> and {user.*} inside code and inline code nodes
@@ -128791,7 +128843,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"*":["about","acceptCharset","accessK
128791
128843
  /******/ // startup
128792
128844
  /******/ // Load entry module and return exports
128793
128845
  /******/ // This entry module used 'module' so it can't be inlined
128794
- /******/ let __webpack_exports__ = __webpack_require__(6009);
128846
+ /******/ let __webpack_exports__ = __webpack_require__(345);
128795
128847
  /******/ module.exports = __webpack_exports__;
128796
128848
  /******/
128797
128849
  /******/ })()