@readme/markdown 14.11.2 → 14.11.4

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
@@ -12631,10 +12631,10 @@ const Tabs = ({ children }) => {
12631
12631
  const tabs = external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().Children.toArray(children);
12632
12632
  return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("div", { className: "TabGroup" },
12633
12633
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("header", null,
12634
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("nav", { className: "TabGroup-nav" }, tabs.map((tab, index) => (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("button", { key: tab.props.title, className: `TabGroup-tab${activeTab === index ? '_active' : ''}`, onClick: () => setActiveTab(index) },
12634
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("nav", { className: "TabGroup-nav" }, tabs.map((tab, index) => (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("button", { key: tab.key, className: `TabGroup-tab${activeTab === index ? '_active' : ''}`, onClick: () => setActiveTab(index) },
12635
12635
  tab.props.icon && (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(components_Icon, { className: "TabGroup-icon", icon: tab.props.icon, iconColor: tab.props.iconColor })),
12636
12636
  tab.props.title))))),
12637
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("section", null, tabs[activeTab])));
12637
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("section", null, tabs.map((tab, index) => (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("div", { key: tab.key, hidden: index !== activeTab }, tab))))));
12638
12638
  };
12639
12639
  /* harmony default export */ const components_Tabs = (Tabs);
12640
12640
 
@@ -54527,6 +54527,21 @@ function evaluate(source, scope = {}) {
54527
54527
  // eslint-disable-next-line no-new-func
54528
54528
  return new Function(...names, `return (${source})`)(...values);
54529
54529
  }
54530
+ /**
54531
+ * Advance a `Point` by the `consumed` substring that follows it, returning the
54532
+ * point at the consumed string's end. Lets split-out sub-nodes carry accurate
54533
+ * document positions so downstream offset shifting stays correct.
54534
+ */
54535
+ const pointAfter = (start, consumed) => {
54536
+ const newlineIndex = consumed.lastIndexOf('\n');
54537
+ const newlineCount = newlineIndex === -1 ? 0 : consumed.split('\n').length - 1;
54538
+ return {
54539
+ line: start.line + newlineCount,
54540
+ // Same line → advance the base column; a later line → column is the run since its newline.
54541
+ column: newlineCount === 0 ? start.column + consumed.length : consumed.length - newlineIndex,
54542
+ offset: (start.offset ?? 0) + consumed.length,
54543
+ };
54544
+ };
54530
54545
  /**
54531
54546
  * Formats the hProperties of a node as a string, so they can be compiled back into JSX/MDX.
54532
54547
  * This currently sets all the values to a string since we process/compile the MDX on the fly
@@ -75795,6 +75810,134 @@ const applyInserts = (html, inserts) => {
75795
75810
  return { value: out + html.slice(cursor), inserts: sorted };
75796
75811
  };
75797
75812
 
75813
+ ;// ./processor/transform/mdxish/tables/escape-crossing-emphasis.ts
75814
+
75815
+
75816
+
75817
+ // Maximal run of a single emphasis delimiter (`_`, `*`, `**`, `***`, …).
75818
+ const EMPHASIS_RUN_RE = /([*_])\1*/g;
75819
+ // String bounds (undefined) count as whitespace, not punctuation, per the
75820
+ // CommonMark flanking definition.
75821
+ const escape_crossing_emphasis_isWhitespace = (ch) => ch === undefined || unicodeWhitespace(ch.charCodeAt(0));
75822
+ const isPunctuation = (ch) => ch !== undefined && unicodePunctuation(ch.charCodeAt(0));
75823
+ /**
75824
+ * Whether a delimiter run can open and/or close emphasis, per CommonMark's
75825
+ * left/right-flanking rules. The extra `_` conditions forbid intraword
75826
+ * emphasis, which keeps `snake_case` from being treated as a delimiter.
75827
+ */
75828
+ const analyzeFlanking = (source, char, start, end) => {
75829
+ const before = source[start - 1];
75830
+ const after = source[end];
75831
+ const leftFlanking = !escape_crossing_emphasis_isWhitespace(after) && (!isPunctuation(after) || escape_crossing_emphasis_isWhitespace(before) || isPunctuation(before));
75832
+ const rightFlanking = !escape_crossing_emphasis_isWhitespace(before) && (!isPunctuation(before) || escape_crossing_emphasis_isWhitespace(after) || isPunctuation(after));
75833
+ if (char === '_') {
75834
+ return {
75835
+ canOpen: leftFlanking && (!rightFlanking || isPunctuation(before)),
75836
+ canClose: rightFlanking && (!leftFlanking || isPunctuation(after)),
75837
+ };
75838
+ }
75839
+ return { canOpen: leftFlanking, canClose: rightFlanking };
75840
+ };
75841
+ /**
75842
+ * Collect HTML tag boundaries (via htmlparser2) and emphasis delimiter runs
75843
+ * (via regex over the masked source, so code spans and escaped `<` are skipped)
75844
+ * into one list ordered by position. At a shared offset a tag opener sorts
75845
+ * before a closer, so a self-closing tag brackets rather than swallows a run.
75846
+ */
75847
+ const collectEvents = (html) => {
75848
+ const masked = maskNonTagRegions(html);
75849
+ const events = [];
75850
+ walkTags(html, {
75851
+ onOpen: ({ start }) => events.push({ kind: 'tagOpen', offset: start }),
75852
+ onClose: ({ start }) => events.push({ kind: 'tagClose', offset: start }),
75853
+ });
75854
+ EMPHASIS_RUN_RE.lastIndex = 0;
75855
+ let match;
75856
+ while ((match = EMPHASIS_RUN_RE.exec(masked)) !== null) {
75857
+ const [run, char] = match;
75858
+ const start = match.index;
75859
+ // eslint-disable-next-line no-continue
75860
+ if (html[start - 1] === '\\')
75861
+ continue; // already escaped
75862
+ events.push({ kind: 'emphasis', offset: start, char, length: run.length, flanking: analyzeFlanking(html, char, start, start + run.length) });
75863
+ }
75864
+ return events.sort((a, b) => a.offset - b.offset || (a.kind === 'tagClose' ? 1 : 0) - (b.kind === 'tagClose' ? 1 : 0));
75865
+ };
75866
+ /**
75867
+ * mdxjs rejects a table when a markdown emphasis run opens at one HTML
75868
+ * tag-nesting depth and closes at another — e.g. `_<ul><li>text_</li></ul>`,
75869
+ * where the `_` opens outside the list but closes inside a `<li>`. It throws
75870
+ * "Expected a closing tag for `<li>` before the end of `emphasis`" and the
75871
+ * whole `<Table>` fails to parse.
75872
+ *
75873
+ * We walk tags and emphasis together, tracking tag depth and a stack of open
75874
+ * emphasis. A delimiter only closes an opener at the same depth; any emphasis
75875
+ * still open when its enclosing tag closes (or at end of input), and any closer
75876
+ * with no same-depth opener, is escaped so mdxjs treats it as literal text.
75877
+ * Scoped to the malformed-retry path.
75878
+ */
75879
+ const escapeCrossingEmphasis = (html) => {
75880
+ const open = [];
75881
+ const orphans = [];
75882
+ let depth = 0;
75883
+ collectEvents(html).forEach(event => {
75884
+ if (event.kind === 'tagOpen') {
75885
+ depth += 1;
75886
+ return;
75887
+ }
75888
+ if (event.kind === 'tagClose') {
75889
+ depth -= 1;
75890
+ // Emphasis opened deeper than the surviving depth was inside the tag that
75891
+ // just closed, so it crosses the boundary.
75892
+ while (open.length > 0 && open[open.length - 1].depth > depth) {
75893
+ const crossed = open.pop();
75894
+ if (crossed)
75895
+ orphans.push(crossed);
75896
+ }
75897
+ return;
75898
+ }
75899
+ const top = open[open.length - 1];
75900
+ if (event.flanking.canClose && top?.char === event.char && top.depth === depth) {
75901
+ open.pop();
75902
+ }
75903
+ else if (event.flanking.canOpen) {
75904
+ open.push({ char: event.char, depth, offset: event.offset, length: event.length });
75905
+ }
75906
+ else if (event.flanking.canClose) {
75907
+ orphans.push({ offset: event.offset, length: event.length });
75908
+ }
75909
+ });
75910
+ orphans.push(...open); // anything still open never closed
75911
+ const inserts = orphans.flatMap(({ offset, length }) => Array.from({ length }, (_unused, i) => ({ offset: offset + i, text: '\\' })));
75912
+ return applyInserts(html, inserts);
75913
+ };
75914
+
75915
+ ;// ./processor/transform/mdxish/tables/escape-stray-less-than.ts
75916
+
75917
+
75918
+ // A `<` only starts a JSX/HTML construct when followed by a tag-name start
75919
+ // (letter, `_`, `$`), a closer `/`, a fragment `>`, or a comment/declaration
75920
+ // `!`. Anything else (whitespace, EOL, a digit, …) is a literal `<` that acorn
75921
+ // rejects with "before name, expected a character that can start a name".
75922
+ const STRAY_LESS_THAN_RE = /<(?![a-zA-Z_$/>!])/g;
75923
+ /**
75924
+ * Escapes stray `<` characters that don't begin a valid tag so the strict mdxjs
75925
+ * parse treats them as literal text instead of throwing (`word <`, `a <1>`).
75926
+ *
75927
+ * Runs against the masked source so `<` inside code spans, legacy `<<var>>`
75928
+ * syntax, or already-escaped `\<` are left untouched.
75929
+ */
75930
+ const escapeStrayLessThan = (html) => {
75931
+ const masked = maskNonTagRegions(html);
75932
+ const inserts = [];
75933
+ STRAY_LESS_THAN_RE.lastIndex = 0;
75934
+ let match;
75935
+ while ((match = STRAY_LESS_THAN_RE.exec(masked)) !== null) {
75936
+ inserts.push({ offset: match.index, text: '\\' });
75937
+ }
75938
+ return applyInserts(html, inserts);
75939
+ };
75940
+
75798
75941
  ;// ./processor/transform/mdxish/tables/normalize-tag-spacing.ts
75799
75942
 
75800
75943
 
@@ -75921,6 +76064,21 @@ const buildOffsetMapper = (inserts) => {
75921
76064
  return repaired - shift;
75922
76065
  };
75923
76066
  };
76067
+ /**
76068
+ * Compose the per-repair offset mappers into one that maps an offset in the
76069
+ * fully-repaired string back to the original. `layers` are in application
76070
+ * order; each maps its own output space to its input space, so we apply them
76071
+ * last-repair-first to peel every edit back to the original coordinates.
76072
+ */
76073
+ const composeOffsetMapper = (layers) => {
76074
+ const mappers = layers.map(buildOffsetMapper);
76075
+ return (repaired) => {
76076
+ let offset = repaired;
76077
+ for (let i = mappers.length - 1; i >= 0; i -= 1)
76078
+ offset = mappers[i](offset);
76079
+ return offset;
76080
+ };
76081
+ };
75924
76082
  /**
75925
76083
  * Map an offset in `source` to its 1-based `{ line, column }`. `lineStarts`
75926
76084
  * is the precomputed array of offsets where each line begins.
@@ -75948,14 +76106,11 @@ const computeLineStarts = (source) => {
75948
76106
  };
75949
76107
  /**
75950
76108
  * Walk `tree`, translating every node's position from the repaired source's
75951
- * coordinate space back to the original source. Offsets are remapped via the
75952
- * insert list; line/column are recomputed from the original source so they
75953
- * remain accurate even if repairs introduced newlines.
76109
+ * coordinate space back to the original source via `mapOffset`. Line/column
76110
+ * are recomputed from the original source so they remain accurate even if
76111
+ * repairs introduced newlines.
75954
76112
  */
75955
- const remapPositionsToOriginal = (tree, originalSource, inserts) => {
75956
- if (inserts.length === 0)
75957
- return;
75958
- const mapOffset = buildOffsetMapper(inserts);
76113
+ const remapWithMapper = (tree, originalSource, mapOffset) => {
75959
76114
  const lineStarts = computeLineStarts(originalSource);
75960
76115
  visit(tree, child => {
75961
76116
  if (child.position?.start) {
@@ -75974,6 +76129,15 @@ const remapPositionsToOriginal = (tree, originalSource, inserts) => {
75974
76129
  }
75975
76130
  });
75976
76131
  };
76132
+ /**
76133
+ * Remap positions produced after a chain of repairs (each applied to the prior
76134
+ * one's output) back to the original source coordinates.
76135
+ */
76136
+ const remapPositionsThroughLayers = (tree, originalSource, layers) => {
76137
+ if (layers.length === 0)
76138
+ return;
76139
+ remapWithMapper(tree, originalSource, composeOffsetMapper(layers));
76140
+ };
75977
76141
 
75978
76142
  ;// ./processor/transform/mdxish/tables/repair-expression-escapes.ts
75979
76143
 
@@ -76273,6 +76437,83 @@ const repairUnclosedTags = (html) => {
76273
76437
  return applyInserts(html, inserts);
76274
76438
  };
76275
76439
 
76440
+ ;// ./processor/transform/mdxish/tables/split-nested-tables.ts
76441
+
76442
+
76443
+ const TOP_LEVEL_TABLE_TAG_RE = /^<(?:table|Table)(?=[\s/>])/;
76444
+ /**
76445
+ * Find every balanced, depth-matched `<table>…</table>` range in an html string.
76446
+ * Uses `walkTags` so `<table>`s inside code spans / fenced blocks (masked away)
76447
+ * are never matched.
76448
+ *
76449
+ * Note: An implicitly-closed table (no `</table>`, so htmlparser2 synthesizes the
76450
+ * close at a later tag) is skipped: splitting there would swallow whatever
76451
+ * followed the table into the fragment and drop it, so we leave such a node
76452
+ * whole for downstream raw-HTML handling instead.
76453
+ */
76454
+ const findTableRanges = (html) => {
76455
+ const ranges = [];
76456
+ let depth = 0;
76457
+ let start = 0;
76458
+ walkTags(html, {
76459
+ onOpen: ({ name, start: openStart, isStrayCloser }) => {
76460
+ if (name.toLowerCase() !== 'table' || isStrayCloser)
76461
+ return;
76462
+ if (depth === 0)
76463
+ start = openStart;
76464
+ depth += 1;
76465
+ },
76466
+ onClose: ({ name, end, implicit }) => {
76467
+ if (implicit || name.toLowerCase() !== 'table' || depth === 0)
76468
+ return;
76469
+ depth -= 1;
76470
+ if (depth === 0)
76471
+ ranges.push({ start, end });
76472
+ },
76473
+ });
76474
+ return ranges;
76475
+ };
76476
+ /**
76477
+ * Given an HTML node that might contain table sequences inside it, split
76478
+ * the node based on the table boundaries so they become a top level node.
76479
+ *
76480
+ * The surrounding raw HTML (the wrapper's open/close tags) would be re-nested
76481
+ * around the parsed tables by rehype-raw.
76482
+ *
76483
+ * Returns null when there is no wrapped table to extract.
76484
+ */
76485
+ const splitHtmlWithNestedTables = (node) => {
76486
+ const { value } = node;
76487
+ // This is a top-level table, so we don't need to split it
76488
+ if (TOP_LEVEL_TABLE_TAG_RE.test(value))
76489
+ return null;
76490
+ // No table text anywhere in the value → skip the htmlparser2 walk entirely.
76491
+ if (!/<\/?table/i.test(value))
76492
+ return null;
76493
+ const ranges = findTableRanges(value);
76494
+ if (ranges.length === 0)
76495
+ return null;
76496
+ const base = node.position?.start;
76497
+ const sliceToHtml = (from, to) => ({
76498
+ type: 'html',
76499
+ value: value.slice(from, to),
76500
+ ...(base && {
76501
+ position: { start: pointAfter(base, value.slice(0, from)), end: pointAfter(base, value.slice(0, to)) },
76502
+ }),
76503
+ });
76504
+ const parts = [];
76505
+ let cursor = 0;
76506
+ ranges.forEach(({ start, end }) => {
76507
+ if (start > cursor)
76508
+ parts.push(sliceToHtml(cursor, start));
76509
+ parts.push(sliceToHtml(start, end)); // starts with `<table` → picked up by the main pass
76510
+ cursor = end;
76511
+ });
76512
+ if (cursor < value.length)
76513
+ parts.push(sliceToHtml(cursor, value.length));
76514
+ return parts;
76515
+ };
76516
+
76276
76517
  ;// ./processor/transform/mdxish/tables/mdxish-tables.ts
76277
76518
 
76278
76519
 
@@ -76292,6 +76533,9 @@ const repairUnclosedTags = (html) => {
76292
76533
 
76293
76534
 
76294
76535
 
76536
+
76537
+
76538
+
76295
76539
 
76296
76540
 
76297
76541
 
@@ -76322,6 +76566,21 @@ const buildTableNodeProcessor = (withMdx) => unified()
76322
76566
  .use(remarkGfm);
76323
76567
  const tableNodeProcessor = buildTableNodeProcessor(true);
76324
76568
  const fallbackTableNodeProcessor = buildTableNodeProcessor(false);
76569
+ // Targeted repairs for tables mdxjs rejects, tried cumulatively (each runs on
76570
+ // the prior's output) since one table can carry independent per-cell defects.
76571
+ // Each was added after seeing real customer content fail to parse:
76572
+ // - repairUnclosedTags: unclosed/orphan HTML tags
76573
+ // - normalizeTagSpacing: a line mixing text and an opening tag
76574
+ // - repairExpressionEscapes: backslash escapes inside a `{…}` expression
76575
+ // - escapeStrayLessThan: a `<` that doesn't begin a valid tag (`word <`)
76576
+ // - escapeCrossingEmphasis: emphasis opening/closing at different tag depths
76577
+ const tableRepairs = [
76578
+ repairUnclosedTags,
76579
+ normalizeTagSpacing,
76580
+ repairExpressionEscapes,
76581
+ escapeStrayLessThan,
76582
+ escapeCrossingEmphasis,
76583
+ ];
76325
76584
  /**
76326
76585
  * Parse the HTML node that contains the full table substring
76327
76586
  * into the table parts (headers, rows, cells).
@@ -76337,10 +76596,10 @@ const parseTableNode = (processor, node, repair) => {
76337
76596
  return undefined;
76338
76597
  }
76339
76598
  // If `node.value` was repaired before parsing, first remap positions back to
76340
- // the original (unrepaired) coordinates via the insert list — otherwise the
76599
+ // the original (unrepaired) coordinates via the insert layers — otherwise the
76341
76600
  // shift would land on synthetic characters and be inaccurate
76342
76601
  if (repair) {
76343
- remapPositionsToOriginal(parsed, repair.originalSource, repair.inserts);
76602
+ remapPositionsThroughLayers(parsed, repair.originalSource, repair.layers);
76344
76603
  }
76345
76604
  // The subparser produces positions relative to `node.value`; shift them by
76346
76605
  // the outer node's offset/line so consumers can slice the full source.
@@ -76437,9 +76696,7 @@ const processTableNode = (node, index, parent, documentPosition) => {
76437
76696
  visit(node, isMDXElement, (child) => {
76438
76697
  if (child.name === 'thead')
76439
76698
  hasThead = true;
76440
- if (tableTags.has(child.name) &&
76441
- Array.isArray(child.attributes) &&
76442
- child.attributes.length > 0) {
76699
+ if (tableTags.has(child.name) && Array.isArray(child.attributes) && child.attributes.length > 0) {
76443
76700
  hasStructuralAttributes = true;
76444
76701
  }
76445
76702
  });
@@ -76550,6 +76807,26 @@ const processTableNode = (node, index, parent, documentPosition) => {
76550
76807
  };
76551
76808
  parent.children[index] = mdNode;
76552
76809
  };
76810
+ /**
76811
+ * Apply `tableRepairs` cumulatively, re-parsing after every change and stopping
76812
+ * once the accumulated result parses. Each layer's inserts are relative to the
76813
+ * string that repair received, so they stay ordered for position remapping.
76814
+ */
76815
+ const repairAndReparse = (node) => {
76816
+ let repairedValue = node.value;
76817
+ const layers = [];
76818
+ let parsed;
76819
+ tableRepairs.some(repair => {
76820
+ const { value, inserts } = repair(repairedValue);
76821
+ if (value === repairedValue)
76822
+ return false;
76823
+ repairedValue = value;
76824
+ layers.push(inserts);
76825
+ parsed = parseTableNode(tableNodeProcessor, { ...node, value: repairedValue }, { layers, originalSource: node.value });
76826
+ return Boolean(parsed);
76827
+ });
76828
+ return parsed;
76829
+ };
76553
76830
  /**
76554
76831
  * Converts JSX Table elements to markdown table nodes and re-parses markdown in cells.
76555
76832
  *
@@ -76562,39 +76839,30 @@ const processTableNode = (node, index, parent, documentPosition) => {
76562
76839
  * is kept as a JSX <Table> element so that remarkRehype can properly handle the flow content.
76563
76840
  */
76564
76841
  const mdxishTables = () => tree => {
76842
+ // Pre-pass: lift `<table>`s wrapped in a raw HTML block out into their own
76843
+ // html nodes so the main pass below treats them like top-level tables.
76844
+ visit(tree, 'html', (_node, index, parent) => {
76845
+ const node = _node;
76846
+ if (typeof index !== 'number' || !parent || !('children' in parent))
76847
+ return;
76848
+ const parts = splitHtmlWithNestedTables(node);
76849
+ if (!parts)
76850
+ return;
76851
+ // The inserted parts can't re-trigger a split (table parts start with
76852
+ // `<table`; the wrapper slices hold no table), so plain in-place splicing
76853
+ // visits each once without looping.
76854
+ parent.children.splice(index, 1, ...parts);
76855
+ });
76565
76856
  visit(tree, 'html', (_node, index, parent) => {
76566
76857
  const node = _node;
76567
76858
  if (typeof index !== 'number' || !parent || !('children' in parent))
76568
76859
  return;
76569
76860
  if (!node.value.startsWith('<Table') && !node.value.startsWith('<table'))
76570
76861
  return;
76571
- // Main logic to transform table node to its parts
76572
76862
  // Because the processor uses remarkMdx, it is stricter in what it accepts
76573
- // and only accepts valid MDX syntax. in the table node.
76574
- // To get around that, we have some fallback logics after trying to repair the table content.
76575
- let parsed = parseTableNode(tableNodeProcessor, node);
76576
- if (!parsed) {
76577
- // Try a sequence of targeted repairs and re-parse
76578
- // after each, stopping at the first that yields a parseable tree:
76579
- // - repairUnclosedTags: unclosed/orphan HTML tags
76580
- // - normalizeTagSpacing: a line mixing text and an opening tag
76581
- // (e.g. `text <div> \n <div> text`)
76582
- // - repairExpressionEscapes: backslash escapes inside a `{…}` expression
76583
- // These repairs are created after seeing real customer content that has failed to parse
76584
- const repairs = [
76585
- repairUnclosedTags,
76586
- normalizeTagSpacing,
76587
- repairExpressionEscapes,
76588
- ];
76589
- // Stops at the first repair that yields a parseable tree
76590
- repairs.some(repair => {
76591
- const { value, inserts } = repair(node.value);
76592
- if (value !== node.value) {
76593
- parsed = parseTableNode(tableNodeProcessor, { ...node, value }, { inserts, originalSource: node.value });
76594
- }
76595
- return Boolean(parsed);
76596
- });
76597
- }
76863
+ // and only accepts valid MDX syntax in the table node. To get around that,
76864
+ // fall back to the cumulative repairs when the first parse fails.
76865
+ const parsed = parseTableNode(tableNodeProcessor, node) ?? repairAndReparse(node);
76598
76866
  if (parsed) {
76599
76867
  // If the table is parsed successfully, we can now process it further
76600
76868
  // to build on the markdown / JSX table
@@ -98743,6 +99011,21 @@ function isActualHtmlTag(tagName, originalExcerpt) {
98743
99011
  return true;
98744
99012
  return false;
98745
99013
  }
99014
+ /**
99015
+ * Re-parsing a component's text child treats it as a standalone document, so
99016
+ * content that happens to start with the literal word `export`/`import`
99017
+ * (e.g. link text like "export Lorem Ipsum") sits at true column 1 and
99018
+ * gets mistaken for an MDX ESM statement, which then fails to parse as JS.
99019
+ * Fall back to `undefined` rather than letting one such child crash the page.
99020
+ */
99021
+ function tryProcessMarkdown(processMarkdown, content) {
99022
+ try {
99023
+ return processMarkdown(content);
99024
+ }
99025
+ catch {
99026
+ return undefined;
99027
+ }
99028
+ }
98746
99029
  /** Parse and replace text children with processed markdown */
98747
99030
  function parseTextChildren(node, processMarkdown, components) {
98748
99031
  if (!node.children?.length)
@@ -98757,7 +99040,9 @@ function parseTextChildren(node, processMarkdown, components) {
98757
99040
  node.properties = { ...node.properties, children: child.value };
98758
99041
  return [];
98759
99042
  }
98760
- const hast = processMarkdown(child.value.trim());
99043
+ const hast = tryProcessMarkdown(processMarkdown, child.value.trim());
99044
+ if (!hast)
99045
+ return [child];
98761
99046
  const children = (hast.children ?? []).filter(isElementContentNode);
98762
99047
  // For inline components, preserve plain text instead of wrapping in <p>
98763
99048
  if (INLINE_COMPONENT_TAGS_LOWER.has(node.tagName.toLowerCase()) && isSingleParagraphTextNode(children)) {
@@ -98831,8 +99116,9 @@ const rehypeMdxishComponents = ({ components, processMarkdown }) => {
98831
99116
  // rehypeRaw strips children from <img> (void element), so we must
98832
99117
  // re-process the caption here, after rehypeRaw.
98833
99118
  if (node.tagName === 'img' && typeof node.properties?.caption === 'string' && !node.children?.length) {
98834
- const captionHast = processMarkdown(node.properties.caption);
98835
- node.children = (captionHast.children ?? []).filter(isElementContentNode);
99119
+ const caption = node.properties.caption;
99120
+ const captionHast = tryProcessMarkdown(processMarkdown, caption);
99121
+ node.children = captionHast ? (captionHast.children ?? []).filter(isElementContentNode) : [{ type: 'text', value: caption }];
98836
99122
  }
98837
99123
  // Skip runtime components and standard HTML tags
98838
99124
  if (RUNTIME_COMPONENT_TAGS.has(node.tagName))
@@ -98865,11 +99151,10 @@ const rehypeMdxishComponents = ({ components, processMarkdown }) => {
98865
99151
  ;// ./processor/plugin/mdxish-handlers.ts
98866
99152
 
98867
99153
 
98868
- // Convert MDX expressions to text nodes (evaluation happens earlier in pipeline)
98869
- const mdxExpressionHandler = (_state, node) => ({
98870
- type: 'text',
98871
- value: node.value || '',
98872
- });
99154
+ // If hChildren is populated, it means the node holds a renderable value (e.g. React)
99155
+ // See evaluate-expressions.ts for more details
99156
+ // Otherwise, it's a simple value and we fall back to text
99157
+ const mdxExpressionHandler = (_state, node) => node.data?.hChildren ?? { type: 'text', value: node.value || '' };
98873
99158
  // Convert MDX JSX elements to a custom mdx-jsx hast node that bypasses rehypeRaw's
98874
99159
  // HTML serialization round-trip; downstream normalization rewrites it to `element`.
98875
99160
  const mdxJsxElementHandler = (state, node) => {
@@ -101936,6 +102221,7 @@ const mdxishInlineMdxComponents = () => tree => {
101936
102221
 
101937
102222
 
101938
102223
 
102224
+
101939
102225
  /** Matches a JSX attribute expression (e.g. `key={i}`) anywhere in a string. */
101940
102226
  const NESTED_ATTR_EXPRESSION_RE = /[\w-]+\s*=\s*\{/;
101941
102227
  /**
@@ -101979,18 +102265,6 @@ const parseSibling = (stack, parent, index, sibling, safeMode) => {
101979
102265
  stack.push(parent);
101980
102266
  }
101981
102267
  };
101982
- /**
101983
- * Advance a point by the substring of source consumed from it.
101984
- */
101985
- const pointAfter = (start, consumed) => {
101986
- const newlineIndex = consumed.lastIndexOf('\n');
101987
- const newlineCount = newlineIndex === -1 ? 0 : consumed.split('\n').length - 1;
101988
- return {
101989
- line: start.line + newlineCount,
101990
- column: newlineCount === 0 ? start.column + consumed.length : consumed.length - newlineIndex,
101991
- offset: start.offset + consumed.length,
101992
- };
101993
- };
101994
102268
  /**
101995
102269
  * Build a position ending at `consumedLength` into the html node's value, so the
101996
102270
  * component doesn't claim trailing content the tokenizer swallowed into one node.
@@ -102493,8 +102767,6 @@ const evaluateExports = () => (tree, file) => {
102493
102767
  };
102494
102768
  /* harmony default export */ const evaluate_exports = (evaluateExports);
102495
102769
 
102496
- // EXTERNAL MODULE: ./node_modules/react-dom/server.browser.js
102497
- var server_browser = __webpack_require__(5848);
102498
102770
  ;// ./lib/utils/mdxish/mdxish-expression.ts
102499
102771
 
102500
102772
 
@@ -102540,26 +102812,185 @@ const evalExpression = (expression, scope) => {
102540
102812
  return evalJsxProgram(program, scope);
102541
102813
  };
102542
102814
 
102543
- ;// ./processor/transform/mdxish/evaluate-expressions.ts
102815
+ // EXTERNAL MODULE: ./node_modules/react-dom/server.browser.js
102816
+ var server_browser = __webpack_require__(5848);
102817
+ ;// ./processor/transform/mdxish/style-object-to-css.ts
102818
+
102819
+ /**
102820
+ * CSS properties React treats as unitless — a bare number stays as-is instead of
102821
+ * getting `px` appended. Mirrors React DOM's `isUnitlessNumber` whitelist.
102822
+ * @see https://github.com/facebook/react/blob/main/packages/react-dom-bindings/src/shared/CSSProperty.js
102823
+ */
102824
+ const UNITLESS_CSS_PROPERTIES = new Set([
102825
+ 'animationIterationCount',
102826
+ 'aspectRatio',
102827
+ 'borderImageOutset',
102828
+ 'borderImageSlice',
102829
+ 'borderImageWidth',
102830
+ 'boxFlex',
102831
+ 'boxFlexGroup',
102832
+ 'boxOrdinalGroup',
102833
+ 'columnCount',
102834
+ 'columns',
102835
+ 'flex',
102836
+ 'flexGrow',
102837
+ 'flexPositive',
102838
+ 'flexShrink',
102839
+ 'flexNegative',
102840
+ 'flexOrder',
102841
+ 'gridArea',
102842
+ 'gridRow',
102843
+ 'gridRowEnd',
102844
+ 'gridRowSpan',
102845
+ 'gridRowStart',
102846
+ 'gridColumn',
102847
+ 'gridColumnEnd',
102848
+ 'gridColumnSpan',
102849
+ 'gridColumnStart',
102850
+ 'fontWeight',
102851
+ 'lineClamp',
102852
+ 'lineHeight',
102853
+ 'opacity',
102854
+ 'order',
102855
+ 'orphans',
102856
+ 'tabSize',
102857
+ 'widows',
102858
+ 'zIndex',
102859
+ 'zoom',
102860
+ 'fillOpacity',
102861
+ 'floodOpacity',
102862
+ 'stopOpacity',
102863
+ 'strokeDasharray',
102864
+ 'strokeDashoffset',
102865
+ 'strokeMiterlimit',
102866
+ 'strokeOpacity',
102867
+ 'strokeWidth',
102868
+ ]);
102869
+ /** Convert a camelCase (or CSS custom property) key into its kebab-case CSS name. */
102870
+ const cssPropertyName = (key) => (key.startsWith('--') ? key : key.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`));
102871
+ /** React appends `px` to non-zero numeric values, except unitless and custom properties. */
102872
+ const cssPropertyValue = (key, value) => typeof value === 'number' && value !== 0 && !key.startsWith('--') && !UNITLESS_CSS_PROPERTIES.has(key)
102873
+ ? `${value}px`
102874
+ : `${value}`;
102875
+ /**
102876
+ * True for a value that should be serialized as a style object rather than passed through
102877
+ * as an already-CSS string. React elements are excluded since they're valid objects too.
102878
+ */
102879
+ const style_object_to_css_isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value) && !external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().isValidElement(value);
102880
+ /**
102881
+ * Serialize a React-style inline style object (`{ color: "red", fontSize: 12 }`) into a
102882
+ * CSS declaration string (`color:red;font-size:12px`), the shape hast/HTML expects for a
102883
+ * `style` attribute. Empty (`undefined`/`null`/`''`) entries are dropped.
102884
+ */
102885
+ const styleObjectToCssText = (style) => Object.entries(style)
102886
+ .filter(([, value]) => value !== undefined && value !== null && value !== '')
102887
+ .map(([key, value]) => `${cssPropertyName(key)}:${cssPropertyValue(key, value)}`)
102888
+ .join(';');
102544
102889
 
102890
+ ;// ./processor/transform/mdxish/react-element-to-hast.ts
102545
102891
 
102546
102892
 
102547
102893
 
102548
- /** True for an array containing at least one React element, e.g. the result of `.map()` returning JSX. */
102549
- const isRenderableElementArray = (value) => Array.isArray(value) && value.some((external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default()).isValidElement);
102550
- /** Given the type of the expression result, create the corresponding mdast node. */
102551
- const createEvaluatedNode = (result, position) => {
102552
- if (result === null || result === undefined) {
102553
- return { type: 'text', value: '', position };
102894
+ // React props that never map to an HTML/hast attribute.
102895
+ const RESERVED_PROPS = new Set(['children', 'key', 'ref']);
102896
+ /**
102897
+ * Translate React props into hast `properties`: reserved and function props (event handlers)
102898
+ * are dropped (known gap), `style` objects flatten to CSS text. Names stay as authored (`className`); the
102899
+ * hast HTML boundary maps them to `class`/`for` downstream.
102900
+ */
102901
+ function propsToHastProperties(props) {
102902
+ const properties = {};
102903
+ Object.entries(props).forEach(([key, value]) => {
102904
+ if (RESERVED_PROPS.has(key) || typeof value === 'function' || value === undefined)
102905
+ return;
102906
+ properties[key] = key === 'style' && style_object_to_css_isPlainObject(value) ? styleObjectToCssText(value) : value;
102907
+ });
102908
+ // Values are resolved React props, wider than hast's HTML-attribute `PropertyValue` union.
102909
+ return properties;
102910
+ }
102911
+ /**
102912
+ * Render an element with React's own renderer as a last resort, wrapped as a hast `raw` node —
102913
+ * the same node type markdown's literal HTML blocks produce, so it re-enters rehypeRaw's
102914
+ * parse5 pass normally. Used for element types this converter can't resolve on its own (wrapped
102915
+ * component types, or a function component that throws when called outside React, e.g. one
102916
+ * using hooks). It's not immune to the invalid-HTML-nesting this module otherwise avoids, but
102917
+ * that's a fair trade against silently dropping the content.
102918
+ */
102919
+ function renderFallbackHtml(element) {
102920
+ try {
102921
+ const rawNode = { type: 'raw', value: (0,server_browser/* renderToStaticMarkup */.qV)(element) };
102922
+ return [rawNode];
102554
102923
  }
102555
- else if (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().isValidElement(result) || isRenderableElementArray(result)) {
102556
- // Convert react elements (or arrays of them, e.g. `.map()` returning JSX) to their HTML
102557
- // representation. This must come before the object check as both are a subset of it.
102558
- return { type: 'html', value: (0,server_browser/* renderToStaticMarkup */.qV)(external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement((external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default()).Fragment, null, result)), position };
102924
+ catch {
102925
+ return [];
102559
102926
  }
102560
- else if (typeof result === 'object') {
102561
- return { type: 'text', value: JSON.stringify(result), position };
102927
+ }
102928
+ /**
102929
+ * Convert a React element tree into hast. Emitting `mdx-jsx` nodes (rehypeRaw passthrough, later normalized to `element`)
102930
+ * preserves nesting that is valid JSX but not valid HTML, which parse5 would otherwise
102931
+ * restructure — e.g. an `<a>` wrapping another `<a>`.
102932
+ * Recursively converts the tree into an array of hast nodes, dealing with arrays and null/undefined/boolean values.
102933
+ */
102934
+ function reactElementToHast(node) {
102935
+ if (Array.isArray(node))
102936
+ return node.flatMap(reactElementToHast);
102937
+ if (node === null || node === undefined || typeof node === 'boolean')
102938
+ return [];
102939
+ if (typeof node === 'string' || typeof node === 'number') {
102940
+ const textNode = { type: 'text', value: String(node) };
102941
+ return [textNode];
102562
102942
  }
102943
+ if (!external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().isValidElement(node))
102944
+ return [];
102945
+ const { type, props } = node;
102946
+ // Fragments contribute their children with no wrapper element.
102947
+ if (type === (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default()).Fragment)
102948
+ return reactElementToHast(props.children);
102949
+ // Resolve function components to their rendered output so the tree is plain intrinsic
102950
+ // elements. If invoking it directly throws (e.g. it uses hooks, which need React's own
102951
+ // render context), fall back to React's renderer for just this subtree.
102952
+ if (typeof type === 'function') {
102953
+ try {
102954
+ return reactElementToHast(type(props));
102955
+ }
102956
+ catch {
102957
+ return renderFallbackHtml(node);
102958
+ }
102959
+ }
102960
+ // Non-intrinsic, non-callable element types — `React.memo`, `React.forwardRef`,
102961
+ // `Context.Provider`/`Consumer`, `React.lazy` — have no `type` we can resolve ourselves.
102962
+ if (typeof type !== 'string')
102963
+ return renderFallbackHtml(node);
102964
+ const mdxJsxNode = {
102965
+ type: 'mdx-jsx',
102966
+ tagName: type,
102967
+ properties: propsToHastProperties(props),
102968
+ children: reactElementToHast(props.children),
102969
+ };
102970
+ return [mdxJsxNode];
102971
+ }
102972
+
102973
+ ;// ./processor/transform/mdxish/evaluate-expressions.ts
102974
+
102975
+
102976
+
102977
+
102978
+ /**
102979
+ * We divide the result of an expression into two categories:
102980
+ * 1. Renderable values: HTML, JSX, e.g. .map() returning JSX
102981
+ * 2. Non-renderable values: a string, number, or object, regular JS values
102982
+ */
102983
+ const isRenderable = (value) => {
102984
+ if (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().isValidElement(value))
102985
+ return true;
102986
+ return Array.isArray(value) && value.some(isRenderable);
102987
+ };
102988
+ /** Turn a non-renderable evaluation result into a text node. */
102989
+ const createTextNode = (result, position) => {
102990
+ if (result === null || result === undefined)
102991
+ return { type: 'text', value: '', position };
102992
+ if (typeof result === 'object')
102993
+ return { type: 'text', value: JSON.stringify(result), position };
102563
102994
  return { type: 'text', value: String(result), position };
102564
102995
  };
102565
102996
  /**
@@ -102575,13 +103006,23 @@ const evaluateExpressions = () => (tree, file) => {
102575
103006
  visit(tree, ['mdxFlowExpression', 'mdxTextExpression'], (node, index, parent) => {
102576
103007
  if (!parent || index === null || index === undefined)
102577
103008
  return;
102578
- const { value, position } = node;
103009
+ const expressionNode = node;
103010
+ const { value, position } = expressionNode;
102579
103011
  const expression = value?.trim();
102580
103012
  if (!expression)
102581
103013
  return;
102582
103014
  try {
102583
103015
  const result = evalExpression(expression, scope);
102584
- parent.children.splice(index, 1, createEvaluatedNode(result, position));
103016
+ if (isRenderable(result)) {
103017
+ // Stash hast built straight from the React tree; `mdxExpressionHandler` emits it and it
103018
+ // passes through rehypeRaw/parse5 step later in the pipeline. This ensures that the
103019
+ // expression result is not parsed by parse5 and fragmenting the nesting that is valid JSX
103020
+ // but invalid HTML — e.g. an `<a>` wrapping `<a>`.
103021
+ expressionNode.data = { ...expressionNode.data, hChildren: reactElementToHast(result) };
103022
+ }
103023
+ else {
103024
+ parent.children.splice(index, 1, createTextNode(result, position));
103025
+ }
102585
103026
  }
102586
103027
  catch (_error) {
102587
103028
  // Evaluation failed — fall back to literal `{...}` text. The expression
@@ -104492,79 +104933,6 @@ function removeJSXComments(content) {
104492
104933
  return content.replace(JSX_COMMENT_REGEX, '');
104493
104934
  }
104494
104935
 
104495
- ;// ./processor/transform/mdxish/style-object-to-css.ts
104496
-
104497
- /**
104498
- * CSS properties React treats as unitless — a bare number stays as-is instead of
104499
- * getting `px` appended. Mirrors React DOM's `isUnitlessNumber` whitelist.
104500
- * @see https://github.com/facebook/react/blob/main/packages/react-dom-bindings/src/shared/CSSProperty.js
104501
- */
104502
- const UNITLESS_CSS_PROPERTIES = new Set([
104503
- 'animationIterationCount',
104504
- 'aspectRatio',
104505
- 'borderImageOutset',
104506
- 'borderImageSlice',
104507
- 'borderImageWidth',
104508
- 'boxFlex',
104509
- 'boxFlexGroup',
104510
- 'boxOrdinalGroup',
104511
- 'columnCount',
104512
- 'columns',
104513
- 'flex',
104514
- 'flexGrow',
104515
- 'flexPositive',
104516
- 'flexShrink',
104517
- 'flexNegative',
104518
- 'flexOrder',
104519
- 'gridArea',
104520
- 'gridRow',
104521
- 'gridRowEnd',
104522
- 'gridRowSpan',
104523
- 'gridRowStart',
104524
- 'gridColumn',
104525
- 'gridColumnEnd',
104526
- 'gridColumnSpan',
104527
- 'gridColumnStart',
104528
- 'fontWeight',
104529
- 'lineClamp',
104530
- 'lineHeight',
104531
- 'opacity',
104532
- 'order',
104533
- 'orphans',
104534
- 'tabSize',
104535
- 'widows',
104536
- 'zIndex',
104537
- 'zoom',
104538
- 'fillOpacity',
104539
- 'floodOpacity',
104540
- 'stopOpacity',
104541
- 'strokeDasharray',
104542
- 'strokeDashoffset',
104543
- 'strokeMiterlimit',
104544
- 'strokeOpacity',
104545
- 'strokeWidth',
104546
- ]);
104547
- /** Convert a camelCase (or CSS custom property) key into its kebab-case CSS name. */
104548
- const cssPropertyName = (key) => (key.startsWith('--') ? key : key.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`));
104549
- /** React appends `px` to non-zero numeric values, except unitless and custom properties. */
104550
- const cssPropertyValue = (key, value) => typeof value === 'number' && value !== 0 && !key.startsWith('--') && !UNITLESS_CSS_PROPERTIES.has(key)
104551
- ? `${value}px`
104552
- : `${value}`;
104553
- /**
104554
- * True for a value that should be serialized as a style object rather than passed through
104555
- * as an already-CSS string. React elements are excluded since they're valid objects too.
104556
- */
104557
- const style_object_to_css_isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value) && !external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().isValidElement(value);
104558
- /**
104559
- * Serialize a React-style inline style object (`{ color: "red", fontSize: 12 }`) into a
104560
- * CSS declaration string (`color:red;font-size:12px`), the shape hast/HTML expects for a
104561
- * `style` attribute. Empty (`undefined`/`null`/`''`) entries are dropped.
104562
- */
104563
- const styleObjectToCssText = (style) => Object.entries(style)
104564
- .filter(([, value]) => value !== undefined && value !== null && value !== '')
104565
- .map(([key, value]) => `${cssPropertyName(key)}:${cssPropertyValue(key, value)}`)
104566
- .join(';');
104567
-
104568
104936
  ;// ./processor/transform/mdxish/resolve-deferred-attribute-expression-props.ts
104569
104937
 
104570
104938
 
@@ -106383,6 +106751,332 @@ const mdxishTags_tags = (doc) => {
106383
106751
  };
106384
106752
  /* harmony default export */ const mdxishTags = (mdxishTags_tags);
106385
106753
 
106754
+ ;// ./lib/mdast-util/html-block-component/index.ts
106755
+ const html_block_component_contextMap = new WeakMap();
106756
+ function findHtmlBlockComponentToken() {
106757
+ const events = this.tokenStack;
106758
+ for (let i = events.length - 1; i >= 0; i -= 1) {
106759
+ if (events[i][0].type === 'htmlBlockComponent')
106760
+ return events[i][0];
106761
+ }
106762
+ return undefined;
106763
+ }
106764
+ function enterHtmlBlockComponent(token) {
106765
+ html_block_component_contextMap.set(token, { chunks: [], lastEndLine: token.start.line });
106766
+ this.enter({ type: 'html', value: '' }, token);
106767
+ }
106768
+ function exitHtmlBlockComponentData(token) {
106769
+ const componentToken = findHtmlBlockComponentToken.call(this);
106770
+ if (!componentToken)
106771
+ return;
106772
+ const ctx = html_block_component_contextMap.get(componentToken);
106773
+ if (ctx) {
106774
+ const gap = token.start.line - ctx.lastEndLine;
106775
+ if (ctx.chunks.length > 0 && gap > 0) {
106776
+ ctx.chunks.push('\n'.repeat(gap));
106777
+ }
106778
+ ctx.chunks.push(this.sliceSerialize(token));
106779
+ ctx.lastEndLine = token.end.line;
106780
+ }
106781
+ }
106782
+ function exitHtmlBlockComponent(token) {
106783
+ const ctx = html_block_component_contextMap.get(token);
106784
+ const node = this.stack[this.stack.length - 1];
106785
+ if (ctx) {
106786
+ node.value = ctx.chunks.join('');
106787
+ html_block_component_contextMap.delete(token);
106788
+ }
106789
+ this.exit(token);
106790
+ }
106791
+ function htmlBlockComponentFromMarkdown() {
106792
+ return {
106793
+ enter: {
106794
+ htmlBlockComponent: enterHtmlBlockComponent,
106795
+ },
106796
+ exit: {
106797
+ htmlBlockComponentData: exitHtmlBlockComponentData,
106798
+ htmlBlockComponent: exitHtmlBlockComponent,
106799
+ },
106800
+ };
106801
+ }
106802
+
106803
+ ;// ./lib/micromark/html-block-component/syntax.ts
106804
+
106805
+
106806
+ const TAG_SUFFIX = [
106807
+ codes.uppercaseT,
106808
+ codes.uppercaseM,
106809
+ codes.uppercaseL,
106810
+ codes.uppercaseB,
106811
+ codes.lowercaseL,
106812
+ codes.lowercaseO,
106813
+ codes.lowercaseC,
106814
+ codes.lowercaseK,
106815
+ ];
106816
+ // ---------------------------------------------------------------------------
106817
+ // Shared tokenizer factory
106818
+ // ---------------------------------------------------------------------------
106819
+ /**
106820
+ * Creates a tokenize function for `<HTMLBlock>...</HTMLBlock>`.
106821
+ *
106822
+ * - **flow** (block-level): supports multiline content via line continuations,
106823
+ * consumes trailing whitespace after the closing tag.
106824
+ * - **text** (inline): single-line only, exits immediately after the closing tag.
106825
+ */
106826
+ function syntax_createTokenize(mode) {
106827
+ return function tokenize(effects, ok, nok) {
106828
+ let depth = 1;
106829
+ function matchChars(chars, onMatch, onFail) {
106830
+ if (chars.length === 0)
106831
+ return onMatch;
106832
+ const next = (code) => {
106833
+ if (code === chars[0]) {
106834
+ effects.consume(code);
106835
+ return matchChars(chars.slice(1), onMatch, onFail);
106836
+ }
106837
+ return onFail(code);
106838
+ };
106839
+ return next;
106840
+ }
106841
+ function matchTagName(onMatch, onFail) {
106842
+ const next = (code) => {
106843
+ if (code === codes.uppercaseH) {
106844
+ effects.consume(code);
106845
+ return matchChars(TAG_SUFFIX, onMatch, onFail);
106846
+ }
106847
+ return onFail(code);
106848
+ };
106849
+ return next;
106850
+ }
106851
+ return start;
106852
+ function start(code) {
106853
+ if (code !== codes.lessThan)
106854
+ return nok(code);
106855
+ effects.enter('htmlBlockComponent');
106856
+ effects.enter('htmlBlockComponentData');
106857
+ effects.consume(code);
106858
+ return matchTagName(afterTagName, nok);
106859
+ }
106860
+ function afterTagName(code) {
106861
+ if (code === codes.greaterThan) {
106862
+ effects.consume(code);
106863
+ return body;
106864
+ }
106865
+ if (code === codes.space || code === codes.horizontalTab) {
106866
+ effects.consume(code);
106867
+ return inAttributes;
106868
+ }
106869
+ if (mode === 'flow' && markdownLineEnding(code)) {
106870
+ effects.exit('htmlBlockComponentData');
106871
+ return attributeContinuationStart(code);
106872
+ }
106873
+ if (code === codes.slash) {
106874
+ effects.consume(code);
106875
+ return selfClose;
106876
+ }
106877
+ return nok(code);
106878
+ }
106879
+ function inAttributes(code) {
106880
+ if (code === codes.greaterThan) {
106881
+ effects.consume(code);
106882
+ return body;
106883
+ }
106884
+ if (code === null) {
106885
+ return nok(code);
106886
+ }
106887
+ if (markdownLineEnding(code)) {
106888
+ if (mode === 'text')
106889
+ return nok(code);
106890
+ effects.exit('htmlBlockComponentData');
106891
+ return attributeContinuationStart(code);
106892
+ }
106893
+ effects.consume(code);
106894
+ return inAttributes;
106895
+ }
106896
+ function attributeContinuationStart(code) {
106897
+ return effects.check(html_block_component_syntax_nonLazyContinuationStart, attributeContinuationNonLazy, continuationAfter)(code);
106898
+ }
106899
+ function attributeContinuationNonLazy(code) {
106900
+ effects.enter(types_types.lineEnding);
106901
+ effects.consume(code);
106902
+ effects.exit(types_types.lineEnding);
106903
+ return attributeContinuationBefore;
106904
+ }
106905
+ function attributeContinuationBefore(code) {
106906
+ if (code === null || markdownLineEnding(code)) {
106907
+ return attributeContinuationStart(code);
106908
+ }
106909
+ effects.enter('htmlBlockComponentData');
106910
+ return inAttributes(code);
106911
+ }
106912
+ function selfClose(code) {
106913
+ if (code === codes.greaterThan) {
106914
+ effects.consume(code);
106915
+ return mode === 'flow' ? afterClose : done(code);
106916
+ }
106917
+ return nok(code);
106918
+ }
106919
+ function body(code) {
106920
+ if (code === null)
106921
+ return nok(code);
106922
+ if (markdownLineEnding(code)) {
106923
+ if (mode === 'text') {
106924
+ // Text constructs operate on paragraph content which spans lines
106925
+ effects.consume(code);
106926
+ return body;
106927
+ }
106928
+ effects.exit('htmlBlockComponentData');
106929
+ return continuationStart(code);
106930
+ }
106931
+ if (code === codes.lessThan) {
106932
+ effects.consume(code);
106933
+ return closeSlash;
106934
+ }
106935
+ effects.consume(code);
106936
+ return body;
106937
+ }
106938
+ function closeSlash(code) {
106939
+ if (code === codes.slash) {
106940
+ effects.consume(code);
106941
+ return matchTagName(closeGt, body);
106942
+ }
106943
+ return matchTagName(openAfterTagName, body)(code);
106944
+ }
106945
+ function openAfterTagName(code) {
106946
+ if (code === codes.greaterThan || code === codes.space || code === codes.horizontalTab) {
106947
+ depth += 1;
106948
+ effects.consume(code);
106949
+ return body;
106950
+ }
106951
+ return body(code);
106952
+ }
106953
+ function closeGt(code) {
106954
+ if (code === codes.greaterThan) {
106955
+ depth -= 1;
106956
+ effects.consume(code);
106957
+ if (depth === 0) {
106958
+ return mode === 'flow' ? afterClose : done(code);
106959
+ }
106960
+ return body;
106961
+ }
106962
+ return body(code);
106963
+ }
106964
+ // -- flow-only states ---------------------------------------------------
106965
+ function afterClose(code) {
106966
+ if (code === null || markdownLineEnding(code)) {
106967
+ return done(code);
106968
+ }
106969
+ if (code === codes.space || code === codes.horizontalTab) {
106970
+ effects.consume(code);
106971
+ return afterClose;
106972
+ }
106973
+ // Reject so the block re-parses as a paragraph, deferring to the
106974
+ // text tokenizer which preserves trailing content in the same line.
106975
+ return nok(code);
106976
+ }
106977
+ // -- flow-only: line continuation ---------------------------------------
106978
+ function continuationStart(code) {
106979
+ return effects.check(html_block_component_syntax_nonLazyContinuationStart, continuationStartNonLazy, continuationAfter)(code);
106980
+ }
106981
+ function continuationStartNonLazy(code) {
106982
+ effects.enter(types_types.lineEnding);
106983
+ effects.consume(code);
106984
+ effects.exit(types_types.lineEnding);
106985
+ return continuationBefore;
106986
+ }
106987
+ function continuationBefore(code) {
106988
+ if (code === null || markdownLineEnding(code)) {
106989
+ return continuationStart(code);
106990
+ }
106991
+ effects.enter('htmlBlockComponentData');
106992
+ return body(code);
106993
+ }
106994
+ function continuationAfter(code) {
106995
+ if (code === null)
106996
+ return nok(code);
106997
+ effects.exit('htmlBlockComponent');
106998
+ return ok(code);
106999
+ }
107000
+ // -- shared exit --------------------------------------------------------
107001
+ function done(_code) {
107002
+ effects.exit('htmlBlockComponentData');
107003
+ effects.exit('htmlBlockComponent');
107004
+ return ok(_code);
107005
+ }
107006
+ };
107007
+ }
107008
+ // ---------------------------------------------------------------------------
107009
+ // Flow construct (block-level)
107010
+ // ---------------------------------------------------------------------------
107011
+ const html_block_component_syntax_nonLazyContinuationStart = {
107012
+ tokenize: html_block_component_syntax_tokenizeNonLazyContinuationStart,
107013
+ partial: true,
107014
+ };
107015
+ function resolveToHtmlBlockComponent(events) {
107016
+ let index = events.length;
107017
+ while (index > 0) {
107018
+ index -= 1;
107019
+ if (events[index][0] === 'enter' && events[index][1].type === 'htmlBlockComponent') {
107020
+ break;
107021
+ }
107022
+ }
107023
+ if (index > 1 && events[index - 2][1].type === types_types.linePrefix) {
107024
+ events[index][1].start = events[index - 2][1].start;
107025
+ events[index + 1][1].start = events[index - 2][1].start;
107026
+ events.splice(index - 2, 2);
107027
+ }
107028
+ return events;
107029
+ }
107030
+ const htmlBlockComponentFlowConstruct = {
107031
+ name: 'htmlBlockComponent',
107032
+ tokenize: syntax_createTokenize('flow'),
107033
+ resolveTo: resolveToHtmlBlockComponent,
107034
+ concrete: true,
107035
+ };
107036
+ function html_block_component_syntax_tokenizeNonLazyContinuationStart(effects, ok, nok) {
107037
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
107038
+ const self = this;
107039
+ return start;
107040
+ function start(code) {
107041
+ if (markdownLineEnding(code)) {
107042
+ effects.enter(types_types.lineEnding);
107043
+ effects.consume(code);
107044
+ effects.exit(types_types.lineEnding);
107045
+ return after;
107046
+ }
107047
+ return nok(code);
107048
+ }
107049
+ function after(code) {
107050
+ if (self.parser.lazy[self.now().line]) {
107051
+ return nok(code);
107052
+ }
107053
+ return ok(code);
107054
+ }
107055
+ }
107056
+ // ---------------------------------------------------------------------------
107057
+ // Text construct (inline)
107058
+ // ---------------------------------------------------------------------------
107059
+ const htmlBlockComponentTextConstruct = {
107060
+ name: 'htmlBlockComponent',
107061
+ tokenize: syntax_createTokenize('text'),
107062
+ };
107063
+ // ---------------------------------------------------------------------------
107064
+ // Extension
107065
+ // ---------------------------------------------------------------------------
107066
+ function htmlBlockComponent() {
107067
+ return {
107068
+ flow: {
107069
+ [codes.lessThan]: [htmlBlockComponentFlowConstruct],
107070
+ },
107071
+ text: {
107072
+ [codes.lessThan]: [htmlBlockComponentTextConstruct],
107073
+ },
107074
+ };
107075
+ }
107076
+
107077
+ ;// ./lib/micromark/html-block-component/index.ts
107078
+
107079
+
106386
107080
  ;// ./lib/utils/extractMagicBlocks.ts
106387
107081
  /**
106388
107082
  * The content matching in this regex captures everything between `[block:TYPE]`
@@ -106449,19 +107143,22 @@ function restoreMagicBlocks(replaced, blocks) {
106449
107143
 
106450
107144
 
106451
107145
 
107146
+
107147
+
106452
107148
  /**
106453
107149
  * Removes Markdown and MDX comments.
106454
107150
  */
106455
107151
  async function stripComments(doc, { mdx, mdxish } = {}) {
106456
107152
  const { replaced, blocks } = extractMagicBlocks(doc);
106457
107153
  const processor = unified();
106458
- // we still require these two extensions because:
107154
+ // we still require these extensions because:
106459
107155
  // 1. we can rely on remarkMdx to parse MDXish
106460
107156
  // 2. we need to parse JSX comments into mdxTextExpression nodes so that the transformers can pick them up
107157
+ // 3. we need to claim <HTMLBlock> before htmlFlow intercepts its inner HTML tags
106461
107158
  if (mdxish) {
106462
107159
  processor
106463
- .data('micromarkExtensions', [jsxTable(), mdxExpression({ allowEmpty: true })])
106464
- .data('fromMarkdownExtensions', [jsxTableFromMarkdown(), mdxExpressionFromMarkdown()])
107160
+ .data('micromarkExtensions', [htmlBlockComponent(), jsxTable(), mdxExpression({ allowEmpty: true })])
107161
+ .data('fromMarkdownExtensions', [htmlBlockComponentFromMarkdown(), jsxTableFromMarkdown(), mdxExpressionFromMarkdown()])
106465
107162
  .data('toMarkdownExtensions', [mdxExpressionToMarkdown()]);
106466
107163
  }
106467
107164
  processor