@readme/markdown 14.6.0 → 14.7.1
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/components/Image/index.tsx +14 -8
- package/components/Image/style.scss +56 -0
- package/dist/lib/constants.d.ts +5 -0
- package/dist/main.css +1 -1
- package/dist/main.css.map +1 -1
- package/dist/main.js +399 -553
- package/dist/main.node.js +397 -551
- package/dist/main.node.js.map +1 -1
- package/dist/processor/transform/mdxish/mdxish-html-blocks.d.ts +14 -1
- package/dist/processor/transform/mdxish/preprocess-jsx-expressions.d.ts +0 -3
- package/dist/processor/utils.d.ts +4 -2
- package/package.json +2 -2
package/dist/main.node.js
CHANGED
|
@@ -24899,11 +24899,20 @@ const Image = (Props) => {
|
|
|
24899
24899
|
lightboxOverlay));
|
|
24900
24900
|
}
|
|
24901
24901
|
if (children || caption) {
|
|
24902
|
-
|
|
24903
|
-
|
|
24904
|
-
|
|
24905
|
-
|
|
24906
|
-
|
|
24902
|
+
// Mirrors the framed pattern: left/right captioned figures float and shrink
|
|
24903
|
+
// to fit so a long caption doesn't widen the float past the image.
|
|
24904
|
+
const isFloating = (align === 'left' || align === 'right') && !noWrap;
|
|
24905
|
+
const figureClass = [
|
|
24906
|
+
(align === 'left' || align === 'right') && `img-figure-${align}`,
|
|
24907
|
+
noWrap && 'img-no-wrap',
|
|
24908
|
+
]
|
|
24909
|
+
.filter(Boolean)
|
|
24910
|
+
.join(' ');
|
|
24911
|
+
const figureStyle = isFloating && typeof width === 'string' && width.endsWith('%') ? { width } : undefined;
|
|
24912
|
+
return (external_react_.createElement("figure", { className: figureClass || undefined, style: figureStyle },
|
|
24913
|
+
closedLightbox(alt || 'Expand image', imgElement),
|
|
24914
|
+
lightboxOverlay,
|
|
24915
|
+
external_react_.createElement("figcaption", null, children || caption)));
|
|
24907
24916
|
}
|
|
24908
24917
|
return (external_react_.createElement(external_react_.Fragment, null,
|
|
24909
24918
|
closedLightbox('Expand image', imgElement),
|
|
@@ -25682,6 +25691,7 @@ const INLINE_COMPONENT_TAGS = new Set(['Anchor', 'Glossary']);
|
|
|
25682
25691
|
/**
|
|
25683
25692
|
* PascalCase tags that have their own dedicated tokenizer / transformer
|
|
25684
25693
|
* and must not be claimed by the generic `mdxComponent` construct.
|
|
25694
|
+
* Subject to change as we add more dedicated tokenizers.
|
|
25685
25695
|
*/
|
|
25686
25696
|
const DEDICATED_COMPONENT_TAGS = ['HTMLBlock', 'Table'];
|
|
25687
25697
|
/**
|
|
@@ -25692,6 +25702,14 @@ const GENERIC_MDX_COMPONENT_EXCLUDED_TAGS = new Set([
|
|
|
25692
25702
|
...DEDICATED_COMPONENT_TAGS,
|
|
25693
25703
|
...INLINE_COMPONENT_TAGS,
|
|
25694
25704
|
]);
|
|
25705
|
+
/**
|
|
25706
|
+
* Tags the micromark `mdxComponent` tokenizer must not claim, which
|
|
25707
|
+
* are inline components and those that have their own dedicated tokenizer
|
|
25708
|
+
*/
|
|
25709
|
+
const TOKENIZER_MDX_COMPONENT_EXCLUDED_TAGS = new Set([
|
|
25710
|
+
'Table',
|
|
25711
|
+
...INLINE_COMPONENT_TAGS,
|
|
25712
|
+
]);
|
|
25695
25713
|
/**
|
|
25696
25714
|
* Lowercased variant of {@link INLINE_COMPONENT_TAGS} for consumers that
|
|
25697
25715
|
* run after rehype (where hast `tagName` is normalized to lowercase).
|
|
@@ -74737,18 +74755,28 @@ const isMDXEsm = (node) => {
|
|
|
74737
74755
|
* Takes an HTML string and formats it for display in the editor. Removes leading/trailing newlines
|
|
74738
74756
|
* and unindents the HTML.
|
|
74739
74757
|
*
|
|
74740
|
-
* @param {string} html - HTML
|
|
74758
|
+
* @param {string} html - cooked HTML payload (callers strip any template-literal backticks first)
|
|
74759
|
+
* @param {number} [openingTagIndent=0] - column the `<HTMLBlock>` opening tag sits at, used to
|
|
74760
|
+
* dedent each content line so its indentation reads relative to the tag, not the line start
|
|
74741
74761
|
* @returns {string} processed HTML
|
|
74742
74762
|
*/
|
|
74743
|
-
function formatHtmlForMdxish(html) {
|
|
74744
|
-
// Remove leading/trailing backticks if present, since they're used to keep the HTML
|
|
74745
|
-
// from being parsed prematurely
|
|
74746
|
-
let processed = html;
|
|
74747
|
-
if (processed.startsWith('`') && processed.endsWith('`')) {
|
|
74748
|
-
processed = processed.slice(1, -1);
|
|
74749
|
-
}
|
|
74763
|
+
function formatHtmlForMdxish(html, openingTagIndent = 0) {
|
|
74750
74764
|
// Removes the leading/trailing newlines
|
|
74751
|
-
let cleaned =
|
|
74765
|
+
let cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
|
|
74766
|
+
// Strip / deindent the lines in the HTML string so that the indents are relative
|
|
74767
|
+
// to the opening HTMLBlock tag, not the literal line start
|
|
74768
|
+
// Keep any deeper indent
|
|
74769
|
+
if (openingTagIndent > 0) {
|
|
74770
|
+
cleaned = cleaned
|
|
74771
|
+
.split('\n')
|
|
74772
|
+
.map(line => {
|
|
74773
|
+
let i = 0;
|
|
74774
|
+
while (i < openingTagIndent && (line[i] === ' ' || line[i] === '\t'))
|
|
74775
|
+
i += 1;
|
|
74776
|
+
return line.slice(i);
|
|
74777
|
+
})
|
|
74778
|
+
.join('\n');
|
|
74779
|
+
}
|
|
74752
74780
|
// Convert literal \n sequences to actual newlines only inside <pre> and <code>.
|
|
74753
74781
|
// Because <pre> needs to respect the newline visual and
|
|
74754
74782
|
// escape characters should be processed in the <code> tag.
|
|
@@ -95905,11 +95933,15 @@ const symmetrizePair = (html, { openStart, openEnd, closeStart, closeEnd }) => {
|
|
|
95905
95933
|
const postCloser = html.slice(closeEnd, closeLine.end);
|
|
95906
95934
|
const openerHasExtras = preOpener.trim().length > 0 || postOpener.trim().length > 0;
|
|
95907
95935
|
const closerHasExtras = preCloser.trim().length > 0 || postCloser.trim().length > 0;
|
|
95908
|
-
//
|
|
95909
|
-
|
|
95936
|
+
// A blank line splits opener/closer into separate paragraphs.
|
|
95937
|
+
// If either tag is attached to surrounding text, mdxjs can fail to match.
|
|
95938
|
+
const spansBlankLine = /\n[^\S\n]*\n/.test(html.slice(openEnd, closeStart));
|
|
95939
|
+
// If both sides are already symmetric, keep as-is.
|
|
95940
|
+
// Exception: attached + blank-line-split pairs still need normalization.
|
|
95941
|
+
if (openerHasExtras === closerHasExtras && !(openerHasExtras && spansBlankLine))
|
|
95910
95942
|
return [];
|
|
95911
|
-
//
|
|
95912
|
-
//
|
|
95943
|
+
// For asymmetric (or attached-but-split) pairs, move side content to its own
|
|
95944
|
+
// line so opener/closer become line-symmetric.
|
|
95913
95945
|
const indentFor = (linePrefix) => linePrefix.match(/^\s*/)?.[0] ?? '';
|
|
95914
95946
|
const inserts = [];
|
|
95915
95947
|
if (openerHasExtras) {
|
|
@@ -96355,6 +96387,7 @@ const repairUnclosedTags = (html) => {
|
|
|
96355
96387
|
|
|
96356
96388
|
|
|
96357
96389
|
|
|
96390
|
+
|
|
96358
96391
|
|
|
96359
96392
|
|
|
96360
96393
|
const isTableCell = (node) => isMDXElement(node) && ['th', 'td'].includes(node.name);
|
|
@@ -96455,6 +96488,15 @@ const processTableNode = (node, index, parent, documentPosition) => {
|
|
|
96455
96488
|
const { align: alignAttr } = getAttrs(node);
|
|
96456
96489
|
const align = Array.isArray(alignAttr) ? alignAttr : null;
|
|
96457
96490
|
let tableHasFlowContent = false;
|
|
96491
|
+
// An `<HTMLBlock>` (still a JSX element here; converted to `html-block` by
|
|
96492
|
+
// `mdxishHtmlBlocks` after this transformer) is block-level content that a
|
|
96493
|
+
// markdown table cell can't represent, so keep the table as a JSX `<Table>`.
|
|
96494
|
+
visit(node, candidate => candidate.type === NodeTypes.htmlBlock ||
|
|
96495
|
+
((candidate.type === 'mdxJsxFlowElement' || candidate.type === 'mdxJsxTextElement') &&
|
|
96496
|
+
candidate.name === 'HTMLBlock'), () => {
|
|
96497
|
+
tableHasFlowContent = true;
|
|
96498
|
+
return EXIT;
|
|
96499
|
+
});
|
|
96458
96500
|
// Re-parse text-only cells through markdown and detect flow content
|
|
96459
96501
|
visit(node, isTableCell, (cell) => {
|
|
96460
96502
|
if (!isTextOnly(cell.children))
|
|
@@ -96537,13 +96579,32 @@ const processTableNode = (node, index, parent, documentPosition) => {
|
|
|
96537
96579
|
// remarkMdx wraps inline `<tr>`s in a paragraph; unwrap one level so the
|
|
96538
96580
|
// hasRow check below sees them.
|
|
96539
96581
|
const flattenSectionChildren = (nodes) => nodes.flatMap(n => n.type === 'paragraph' && 'children' in n && Array.isArray(n.children) ? n.children : [n]);
|
|
96540
|
-
|
|
96541
|
-
|
|
96582
|
+
// Iterate the table's direct children in document order. Rows may live
|
|
96583
|
+
// inside a `<thead>`/`<tbody>` section, or sit bare directly under the table
|
|
96584
|
+
// with no section wrapper — both are collected here so the first row becomes
|
|
96585
|
+
// the markdown table header.
|
|
96586
|
+
const tableChildren = flattenSectionChildren(node.children);
|
|
96587
|
+
tableChildren.forEach(child => {
|
|
96588
|
+
if (!isMDXElement(child))
|
|
96589
|
+
return;
|
|
96590
|
+
const childElement = child;
|
|
96591
|
+
// Path for a `<tr>` directly under the table, without a `<thead>`/`<tbody>` wrapper.
|
|
96592
|
+
if (childElement.name === 'tr') {
|
|
96593
|
+
children.push({
|
|
96594
|
+
type: 'tableRow',
|
|
96595
|
+
children: collectCells(childElement),
|
|
96596
|
+
position: childElement.position,
|
|
96597
|
+
});
|
|
96598
|
+
return;
|
|
96599
|
+
}
|
|
96600
|
+
// Path for when the rows are wrapped in a `<thead>`/`<tbody>`
|
|
96601
|
+
// We visit & collect the entire rows under them directly here
|
|
96602
|
+
if (childElement.name !== 'thead' && childElement.name !== 'tbody')
|
|
96542
96603
|
return;
|
|
96543
|
-
const sectionChildren = flattenSectionChildren(
|
|
96604
|
+
const sectionChildren = flattenSectionChildren(childElement.children);
|
|
96544
96605
|
const hasRow = sectionChildren.some(c => isMDXElement(c) && c.name === 'tr');
|
|
96545
96606
|
if (hasRow) {
|
|
96546
|
-
visit(
|
|
96607
|
+
visit(childElement, isMDXElement, (row) => {
|
|
96547
96608
|
if (row.name !== 'tr')
|
|
96548
96609
|
return;
|
|
96549
96610
|
children.push({
|
|
@@ -96557,7 +96618,7 @@ const processTableNode = (node, index, parent, documentPosition) => {
|
|
|
96557
96618
|
// No `<tr>`, chunk bare cells into rows using the prior row's column
|
|
96558
96619
|
// count (e.g. from `<thead>`), so 4 bare `<td>`s under a 2-col header
|
|
96559
96620
|
// become 2 rows of 2.
|
|
96560
|
-
const cells = collectCells(
|
|
96621
|
+
const cells = collectCells(childElement);
|
|
96561
96622
|
if (cells.length === 0)
|
|
96562
96623
|
return;
|
|
96563
96624
|
const cols = children[0]?.children?.length || cells.length;
|
|
@@ -96565,11 +96626,12 @@ const processTableNode = (node, index, parent, documentPosition) => {
|
|
|
96565
96626
|
children.push({
|
|
96566
96627
|
type: 'tableRow',
|
|
96567
96628
|
children: cells.slice(i, i + cols),
|
|
96568
|
-
position:
|
|
96629
|
+
position: childElement.position,
|
|
96569
96630
|
});
|
|
96570
96631
|
}
|
|
96571
96632
|
}
|
|
96572
96633
|
});
|
|
96634
|
+
// Output the markdown table node
|
|
96573
96635
|
const firstRow = children[0];
|
|
96574
96636
|
const columnCount = firstRow?.children?.length || 0;
|
|
96575
96637
|
const alignArray = align && columnCount > 0
|
|
@@ -121095,7 +121157,7 @@ function createTokenize(mode) {
|
|
|
121095
121157
|
return tagNameRest;
|
|
121096
121158
|
}
|
|
121097
121159
|
// Tag name complete — check exclusions
|
|
121098
|
-
if (
|
|
121160
|
+
if (TOKENIZER_MDX_COMPONENT_EXCLUDED_TAGS.has(tagName)) {
|
|
121099
121161
|
return nok(code);
|
|
121100
121162
|
}
|
|
121101
121163
|
depth = 1;
|
|
@@ -123186,557 +123248,158 @@ const magicBlockTransformer = (options = {}) => tree => {
|
|
|
123186
123248
|
};
|
|
123187
123249
|
/* harmony default export */ const magic_block_transformer = (magicBlockTransformer);
|
|
123188
123250
|
|
|
123189
|
-
;// ./
|
|
123190
|
-
/**
|
|
123191
|
-
* Matches a JSX comment: `{/*`, content, `*\/}` — no whitespace tolerated
|
|
123192
|
-
* between the braces and the comment markers.
|
|
123193
|
-
*
|
|
123194
|
-
* This grammar is mirrored by the flow tokenizer in ./syntax.ts. Any change
|
|
123195
|
-
* here needs a mirror change in the state machine; the parity test in
|
|
123196
|
-
* __tests__/lib/micromark/jsx-comment-pattern-parity.test.ts locks the two
|
|
123197
|
-
* together so they can't silently drift.
|
|
123198
|
-
*/
|
|
123199
|
-
const JSX_COMMENT_REGEX = /\{\/\*[^*]*(?:\*(?!\/)[^*]*)*\*\/\}/g;
|
|
123251
|
+
;// ./processor/transform/mdxish/mdxish-html-blocks.ts
|
|
123200
123252
|
|
|
123201
|
-
;// ./processor/transform/mdxish/preprocess-jsx-expressions.ts
|
|
123202
123253
|
|
|
123203
123254
|
|
|
123204
|
-
//
|
|
123205
|
-
|
|
123206
|
-
|
|
123207
|
-
|
|
123208
|
-
|
|
123209
|
-
|
|
123210
|
-
|
|
123211
|
-
// Base64 decode (Node.js + browser compatible)
|
|
123212
|
-
function base64Decode(str) {
|
|
123213
|
-
if (typeof Buffer !== 'undefined') {
|
|
123214
|
-
return Buffer.from(str, 'base64').toString('utf-8');
|
|
123215
|
-
}
|
|
123216
|
-
return decodeURIComponent(escape(atob(str)));
|
|
123217
|
-
}
|
|
123218
|
-
// Markers for protected HTMLBlock content (HTML comments avoid markdown parsing issues)
|
|
123219
|
-
const HTML_BLOCK_CONTENT_START = '<!--RDMX_HTMLBLOCK:';
|
|
123220
|
-
const HTML_BLOCK_CONTENT_END = ':RDMX_HTMLBLOCK-->';
|
|
123255
|
+
// `<HTMLBlock …>{`…`}</HTMLBlock>` embedded inside a raw HTML block (e.g. a
|
|
123256
|
+
// single-line `<div>…</div>`). CommonMark slurps the whole div as one `html`
|
|
123257
|
+
// node, so the tokenizer never sees the HTMLBlock — we recover it here.
|
|
123258
|
+
const RAW_HTML_BLOCK_RE = /<HTMLBlock\b([^>]*)>\s*\{\s*`((?:[^`\\]|\\.)*)`\s*\}\s*<\/HTMLBlock>/g;
|
|
123259
|
+
// Opening `<HTMLBlock …>` as its own `html` node — produced inside a paragraph
|
|
123260
|
+
// when an HTMLBlock appears inline alongside text.
|
|
123261
|
+
const HTML_BLOCK_OPEN_RE = /^<HTMLBlock\b([^>]*)>$/;
|
|
123221
123262
|
/**
|
|
123222
|
-
*
|
|
123223
|
-
*
|
|
123224
|
-
* @param content
|
|
123225
|
-
* @returns Content with HTMLBlock template literals base64 encoded in HTML comments
|
|
123226
|
-
* @example
|
|
123227
|
-
* ```typescript
|
|
123228
|
-
* const input = '<HTMLBlock>{`<script>alert("xss")</script>`}</HTMLBlock>';
|
|
123229
|
-
* protectHTMLBlockContent(input)
|
|
123230
|
-
* // Returns: '<HTMLBlock><!--RDMX_HTMLBLOCK:PHNjcmlwdD5hbGVydCgieHNzIik8L3NjcmlwdD4=:RDMX_HTMLBLOCK--></HTMLBlock>'
|
|
123231
|
-
* ```
|
|
123263
|
+
* Builds the canonical `html-block` MDAST node the renderer expects.
|
|
123232
123264
|
*/
|
|
123233
|
-
|
|
123234
|
-
|
|
123235
|
-
|
|
123236
|
-
|
|
123237
|
-
|
|
123238
|
-
|
|
123265
|
+
const createHtmlBlockNode = (html, position, runScripts, safeMode) => ({
|
|
123266
|
+
position,
|
|
123267
|
+
children: [{ type: 'text', value: html }],
|
|
123268
|
+
type: NodeTypes.htmlBlock,
|
|
123269
|
+
data: {
|
|
123270
|
+
hName: 'html-block',
|
|
123271
|
+
hProperties: {
|
|
123272
|
+
html,
|
|
123273
|
+
...(runScripts !== undefined && { runScripts }),
|
|
123274
|
+
...(safeMode !== undefined && { safeMode }),
|
|
123275
|
+
},
|
|
123276
|
+
},
|
|
123277
|
+
});
|
|
123239
123278
|
/**
|
|
123240
|
-
*
|
|
123241
|
-
*
|
|
123242
|
-
* @param content
|
|
123243
|
-
* @returns Content with JSX comments removed
|
|
123244
|
-
* @example
|
|
123245
|
-
* ```typescript
|
|
123246
|
-
* removeJSXComments('Text { /* comment *\/ } more text')
|
|
123247
|
-
* // Returns: 'Text more text'
|
|
123248
|
-
* ```
|
|
123279
|
+
* Reads the cooked string out of a brace expression wrapping a single template
|
|
123280
|
+
* literal (`` `<p>n</p>` `` → `<p>n</p>`).
|
|
123249
123281
|
*/
|
|
123250
|
-
|
|
123251
|
-
|
|
123252
|
-
|
|
123253
|
-
const
|
|
123254
|
-
|
|
123255
|
-
//
|
|
123256
|
-
|
|
123257
|
-
|
|
123282
|
+
const extractTemplateLiteral = (value) => {
|
|
123283
|
+
if (!value)
|
|
123284
|
+
return '';
|
|
123285
|
+
const match = value.trim().match(/^`([\s\S]*)`$/);
|
|
123286
|
+
// Non-template-literal bodies (e.g. `{someVar}`) are malformed mdxish input;
|
|
123287
|
+
// returning '' beats shipping JS identifier source as an HTML payload.
|
|
123288
|
+
return match ? match[1] : '';
|
|
123289
|
+
};
|
|
123290
|
+
const toRunScripts = (raw) => raw === 'true' ? true : raw === 'false' ? false : raw;
|
|
123291
|
+
/** Reads an attribute from a raw `<HTMLBlock …>` attribute string. */
|
|
123292
|
+
const rawAttr = (attrs, name) => {
|
|
123293
|
+
const quoted = attrs.match(new RegExp(`\\b${name}\\s*=\\s*"([^"]*)"`));
|
|
123294
|
+
if (quoted)
|
|
123295
|
+
return quoted[1];
|
|
123296
|
+
const expr = attrs.match(new RegExp(`\\b${name}\\s*=\\s*\\{(true|false)\\}`));
|
|
123297
|
+
if (expr)
|
|
123298
|
+
return expr[1];
|
|
123299
|
+
return new RegExp(`\\b${name}\\b`).test(attrs) ? 'true' : undefined;
|
|
123300
|
+
};
|
|
123301
|
+
/** Reads an attribute from a parsed `<HTMLBlock>` JSX element. */
|
|
123302
|
+
const jsxAttr = (element, name) => {
|
|
123303
|
+
const attr = element.attributes.find(a => a.type === 'mdxJsxAttribute' && a.name === name);
|
|
123304
|
+
if (!attr || attr.type !== 'mdxJsxAttribute')
|
|
123305
|
+
return undefined;
|
|
123306
|
+
if (typeof attr.value === 'string')
|
|
123307
|
+
return attr.value;
|
|
123308
|
+
if (attr.value && typeof attr.value === 'object' && 'value' in attr.value)
|
|
123309
|
+
return attr.value.value;
|
|
123310
|
+
return 'true'; // bare boolean attribute, e.g. <HTMLBlock runScripts />
|
|
123311
|
+
};
|
|
123312
|
+
/** Builds an `html-block` from a raw attribute string and (unparsed) body. */
|
|
123313
|
+
const htmlBlockFromRaw = (attrs, html, position, openingTagIndent = 0) => createHtmlBlockNode(formatHtmlForMdxish(html, openingTagIndent), position, toRunScripts(rawAttr(attrs, 'runScripts')), rawAttr(attrs, 'safeMode'));
|
|
123258
123314
|
/**
|
|
123259
|
-
*
|
|
123260
|
-
*
|
|
123315
|
+
* Splits a raw `html` node that embeds one or more `<HTMLBlock>`s into
|
|
123316
|
+
* `[html before, html-block, html after, …]`. Returns null when there is none.
|
|
123261
123317
|
*
|
|
123262
|
-
*
|
|
123263
|
-
*
|
|
123264
|
-
* escape — so we leave that case to the brace balancer.
|
|
123318
|
+
* `String.split` on a regex with capture groups interleaves the captures into
|
|
123319
|
+
* the result, so segments arrive as `[text, attrs, body, text, attrs, body, …]`.
|
|
123265
123320
|
*/
|
|
123266
|
-
|
|
123267
|
-
const
|
|
123268
|
-
|
|
123269
|
-
|
|
123270
|
-
|
|
123271
|
-
|
|
123272
|
-
|
|
123273
|
-
|
|
123274
|
-
|
|
123275
|
-
|
|
123276
|
-
|
|
123277
|
-
|
|
123278
|
-
|
|
123279
|
-
|
|
123280
|
-
});
|
|
123281
|
-
return { htmlElements, protectedContent };
|
|
123282
|
-
}
|
|
123283
|
-
function restoreHTMLElements(content, htmlElements) {
|
|
123284
|
-
if (htmlElements.length === 0)
|
|
123285
|
-
return content;
|
|
123286
|
-
return content.replace(HTML_ELEM_PLACEHOLDER, (_m, idx) => htmlElements[parseInt(idx, 10)]);
|
|
123287
|
-
}
|
|
123288
|
-
/**
|
|
123289
|
-
* Escapes unbalanced and paragraph-spanning braces so MDX doesn't trip on them.
|
|
123290
|
-
*/
|
|
123291
|
-
function escapeProblematicBraces(content) {
|
|
123292
|
-
const { htmlElements, protectedContent } = protectHTMLElements(content);
|
|
123293
|
-
let strDelim = null;
|
|
123294
|
-
let strEscaped = false;
|
|
123295
|
-
// Track position of last newline (outside strings) to detect blank lines
|
|
123296
|
-
// -2 means no recent newline
|
|
123297
|
-
let lastNewlinePos = -2;
|
|
123298
|
-
// Character state machine trackers
|
|
123299
|
-
const toEscape = new Set();
|
|
123300
|
-
// Convert to array of Unicode code points so that emojis and multi-byte characters are correctly tracked
|
|
123301
|
-
const chars = Array.from(protectedContent);
|
|
123302
|
-
const openStack = [];
|
|
123303
|
-
for (let i = 0; i < chars.length; i += 1) {
|
|
123304
|
-
const ch = chars[i];
|
|
123305
|
-
// Track string delimiters inside expressions to ignore braces within them
|
|
123306
|
-
if (openStack.length > 0) {
|
|
123307
|
-
if (strDelim) {
|
|
123308
|
-
if (strEscaped)
|
|
123309
|
-
strEscaped = false;
|
|
123310
|
-
else if (ch === '\\')
|
|
123311
|
-
strEscaped = true;
|
|
123312
|
-
else if (ch === strDelim)
|
|
123313
|
-
strDelim = null;
|
|
123314
|
-
// eslint-disable-next-line no-continue
|
|
123315
|
-
continue;
|
|
123316
|
-
}
|
|
123317
|
-
if (ch === '"' || ch === "'" || ch === '`') {
|
|
123318
|
-
strDelim = ch;
|
|
123319
|
-
// eslint-disable-next-line no-continue
|
|
123320
|
-
continue;
|
|
123321
|
-
}
|
|
123322
|
-
if (ch === '\n') {
|
|
123323
|
-
if (lastNewlinePos >= 0) {
|
|
123324
|
-
const between = chars.slice(lastNewlinePos + 1, i).join('');
|
|
123325
|
-
if (/^[ \t]*$/.test(between)) {
|
|
123326
|
-
openStack.forEach(entry => { entry.hasBlankLine = true; });
|
|
123327
|
-
}
|
|
123328
|
-
}
|
|
123329
|
-
lastNewlinePos = i;
|
|
123330
|
-
}
|
|
123331
|
-
}
|
|
123332
|
-
// Skip already-escaped braces (odd run of preceding backslashes).
|
|
123333
|
-
if (ch === '{' || ch === '}') {
|
|
123334
|
-
let bs = 0;
|
|
123335
|
-
for (let j = i - 1; j >= 0 && chars[j] === '\\'; j -= 1)
|
|
123336
|
-
bs += 1;
|
|
123337
|
-
if (bs % 2 === 1) {
|
|
123338
|
-
// eslint-disable-next-line no-continue
|
|
123339
|
-
continue;
|
|
123340
|
-
}
|
|
123341
|
-
}
|
|
123342
|
-
if (ch === '{') {
|
|
123343
|
-
// `=` (after whitespace) before `{` ⇒ JSX attribute expression. The
|
|
123344
|
-
// mdxComponent tokenizer captures the whole component, so blank lines
|
|
123345
|
-
// inside attribute values are harmless. Nested `{` inherits the flag.
|
|
123346
|
-
let isAttrExpr = false;
|
|
123347
|
-
for (let j = i - 1; j >= 0; j -= 1) {
|
|
123348
|
-
const pc = chars[j];
|
|
123349
|
-
if (pc === '=') {
|
|
123350
|
-
isAttrExpr = true;
|
|
123351
|
-
break;
|
|
123352
|
-
}
|
|
123353
|
-
if (pc !== ' ' && pc !== '\t')
|
|
123354
|
-
break;
|
|
123355
|
-
}
|
|
123356
|
-
// Nested `{ ... }` inside an attribute value (e.g. `data={[{ ... }]}` or
|
|
123357
|
-
// `data={{ a: { b: 1 } }}`) must inherit the same exemption; only the
|
|
123358
|
-
// outer `{` is directly after `=`.
|
|
123359
|
-
if (!isAttrExpr && openStack.length > 0 && openStack[openStack.length - 1].isAttrExpr) {
|
|
123360
|
-
isAttrExpr = true;
|
|
123361
|
-
}
|
|
123362
|
-
openStack.push({ pos: i, hasBlankLine: false, isAttrExpr });
|
|
123363
|
-
lastNewlinePos = -2;
|
|
123364
|
-
}
|
|
123365
|
-
else if (ch === '}') {
|
|
123366
|
-
if (openStack.length > 0) {
|
|
123367
|
-
const entry = openStack.pop();
|
|
123368
|
-
// Pure `{/* ... */}` comments are handled downstream by the jsxComment
|
|
123369
|
-
// tokenizer — escaping their braces would prevent it from running.
|
|
123370
|
-
const isPureJsxComment = chars[entry.pos + 1] === '/' &&
|
|
123371
|
-
chars[entry.pos + 2] === '*' &&
|
|
123372
|
-
chars[i - 1] === '/' &&
|
|
123373
|
-
chars[i - 2] === '*';
|
|
123374
|
-
if (entry.hasBlankLine && !isPureJsxComment && !entry.isAttrExpr) {
|
|
123375
|
-
toEscape.add(entry.pos);
|
|
123376
|
-
toEscape.add(i);
|
|
123377
|
-
}
|
|
123378
|
-
}
|
|
123379
|
-
else {
|
|
123380
|
-
toEscape.add(i);
|
|
123381
|
-
}
|
|
123321
|
+
const splitRawHtmlBlocks = (node) => {
|
|
123322
|
+
const segments = node.value.split(RAW_HTML_BLOCK_RE);
|
|
123323
|
+
if (segments.length === 1)
|
|
123324
|
+
return null; // no <HTMLBlock> present
|
|
123325
|
+
const parts = [];
|
|
123326
|
+
for (let i = 0; i < segments.length; i += 3) {
|
|
123327
|
+
const [text, attrs, body] = segments.slice(i, i + 3);
|
|
123328
|
+
if (text)
|
|
123329
|
+
parts.push({ type: 'html', value: text });
|
|
123330
|
+
if (body !== undefined) {
|
|
123331
|
+
// The opening tag's column equals the length of the line it starts on
|
|
123332
|
+
// (the text run since the previous newline preceding the match).
|
|
123333
|
+
const openingTagIndent = text.slice(text.lastIndexOf('\n') + 1).length;
|
|
123334
|
+
parts.push(htmlBlockFromRaw(attrs, body, node.position, openingTagIndent));
|
|
123382
123335
|
}
|
|
123383
123336
|
}
|
|
123384
|
-
|
|
123385
|
-
|
|
123386
|
-
// Reconstruct the content with the escaped braces.
|
|
123387
|
-
const escapedContent = toEscape.size === 0 ? protectedContent : chars.map((ch, i) => (toEscape.has(i) ? `\\${ch}` : ch)).join('');
|
|
123388
|
-
return restoreHTMLElements(escapedContent, htmlElements);
|
|
123389
|
-
}
|
|
123337
|
+
return parts;
|
|
123338
|
+
};
|
|
123390
123339
|
/**
|
|
123391
|
-
*
|
|
123340
|
+
* Converts every `<HTMLBlock>` shape that survives parsing into the canonical
|
|
123341
|
+
* `html-block` MDAST node, reading the body from the tokenizer's template-literal
|
|
123342
|
+
* expression. Three shapes occur:
|
|
123392
123343
|
*
|
|
123393
|
-
* JSX
|
|
123394
|
-
*
|
|
123395
|
-
*
|
|
123344
|
+
* 1. JSX element (`mdxJsxFlowElement`/`mdxJsxTextElement`) — multiline/block
|
|
123345
|
+
* context and table cells (after their remarkMdx re-parse).
|
|
123346
|
+
* 2. Raw `html` blob (`splitRawHtmlBlocks`) — single-line top-level, or nested
|
|
123347
|
+
* in raw HTML like an inline `<div>`.
|
|
123348
|
+
* 3. Inline-in-paragraph — split into `html` + expression + `html` siblings.
|
|
123396
123349
|
*
|
|
123397
|
-
*
|
|
123398
|
-
*
|
|
123399
|
-
|
|
123400
|
-
|
|
123401
|
-
let processed = protectHTMLBlockContent(content);
|
|
123402
|
-
const { protectedCode, protectedContent } = protectCodeBlocks(processed);
|
|
123403
|
-
processed = escapeProblematicBraces(protectedContent);
|
|
123404
|
-
processed = restoreCodeBlocks(processed, protectedCode);
|
|
123405
|
-
return processed;
|
|
123406
|
-
}
|
|
123407
|
-
|
|
123408
|
-
;// ./processor/transform/mdxish/mdxish-html-blocks.ts
|
|
123409
|
-
|
|
123410
|
-
|
|
123411
|
-
|
|
123412
|
-
|
|
123413
|
-
/**
|
|
123414
|
-
* Decodes HTMLBlock content that was protected during preprocessing.
|
|
123415
|
-
* Content is wrapped in <!--RDMX_HTMLBLOCK:base64:RDMX_HTMLBLOCK-->
|
|
123416
|
-
*/
|
|
123417
|
-
function decodeProtectedContent(content) {
|
|
123418
|
-
// Escape special regex characters in the markers
|
|
123419
|
-
const startEscaped = HTML_BLOCK_CONTENT_START.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
123420
|
-
const endEscaped = HTML_BLOCK_CONTENT_END.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
123421
|
-
const markerRegex = new RegExp(`${startEscaped}([A-Za-z0-9+/=]+)${endEscaped}`, 'g');
|
|
123422
|
-
return content.replace(markerRegex, (_match, encoded) => {
|
|
123423
|
-
try {
|
|
123424
|
-
return base64Decode(encoded);
|
|
123425
|
-
}
|
|
123426
|
-
catch {
|
|
123427
|
-
return encoded;
|
|
123428
|
-
}
|
|
123429
|
-
});
|
|
123430
|
-
}
|
|
123431
|
-
/**
|
|
123432
|
-
* Collects text content from a node and its children recursively
|
|
123433
|
-
*/
|
|
123434
|
-
function collectTextContent(node) {
|
|
123435
|
-
const parts = [];
|
|
123436
|
-
if (node.type === 'text' && node.value) {
|
|
123437
|
-
parts.push(node.value);
|
|
123438
|
-
}
|
|
123439
|
-
else if (node.type === 'html' && node.value) {
|
|
123440
|
-
parts.push(node.value);
|
|
123441
|
-
}
|
|
123442
|
-
else if (node.type === 'inlineCode' && node.value) {
|
|
123443
|
-
parts.push(node.value);
|
|
123444
|
-
}
|
|
123445
|
-
else if (node.type === 'code' && node.value) {
|
|
123446
|
-
// Reconstruct code fence syntax (markdown parser consumes opening ```)
|
|
123447
|
-
const lang = node.lang || '';
|
|
123448
|
-
const fence = `\`\`\`${lang ? `${lang}\n` : ''}`;
|
|
123449
|
-
parts.push(fence);
|
|
123450
|
-
parts.push(node.value);
|
|
123451
|
-
// Add newline before closing fence if missing
|
|
123452
|
-
const closingFence = node.value.endsWith('\n') ? '```' : '\n```';
|
|
123453
|
-
parts.push(closingFence);
|
|
123454
|
-
}
|
|
123455
|
-
else if (node.children && Array.isArray(node.children)) {
|
|
123456
|
-
node.children.forEach(child => {
|
|
123457
|
-
if (typeof child === 'object' && child !== null) {
|
|
123458
|
-
parts.push(collectTextContent(child));
|
|
123459
|
-
}
|
|
123460
|
-
});
|
|
123461
|
-
}
|
|
123462
|
-
return parts.join('');
|
|
123463
|
-
}
|
|
123464
|
-
/**
|
|
123465
|
-
* Extracts boolean attribute from HTML tag. Handles JSX (safeMode={true}) and string (safeMode="true") syntax.
|
|
123466
|
-
* Returns "true"/"false" string to survive rehypeRaw serialization.
|
|
123467
|
-
*/
|
|
123468
|
-
function extractBooleanAttr(attrs, name) {
|
|
123469
|
-
// Try JSX syntax: name={true|false}
|
|
123470
|
-
const jsxMatch = attrs.match(new RegExp(`${name}=\\{(true|false)\\}`));
|
|
123471
|
-
if (jsxMatch) {
|
|
123472
|
-
return jsxMatch[1];
|
|
123473
|
-
}
|
|
123474
|
-
// Try string syntax: name="true"|true
|
|
123475
|
-
const stringMatch = attrs.match(new RegExp(`${name}="?(true|false)"?`));
|
|
123476
|
-
if (stringMatch) {
|
|
123477
|
-
return stringMatch[1];
|
|
123478
|
-
}
|
|
123479
|
-
return undefined;
|
|
123480
|
-
}
|
|
123481
|
-
/**
|
|
123482
|
-
* Extracts runScripts attribute from HTML tag. Returns boolean for "true"/"false", string for other values, or undefined if not found.
|
|
123483
|
-
*/
|
|
123484
|
-
function extractRunScriptsAttr(attrs) {
|
|
123485
|
-
const runScriptsMatch = attrs.match(/runScripts="?([^">\s]+)"?/);
|
|
123486
|
-
if (!runScriptsMatch) {
|
|
123487
|
-
return undefined;
|
|
123488
|
-
}
|
|
123489
|
-
const value = runScriptsMatch[1];
|
|
123490
|
-
if (value === 'true') {
|
|
123491
|
-
return true;
|
|
123492
|
-
}
|
|
123493
|
-
if (value === 'false') {
|
|
123494
|
-
return false;
|
|
123495
|
-
}
|
|
123496
|
-
return value;
|
|
123497
|
-
}
|
|
123498
|
-
/**
|
|
123499
|
-
* Creates an HTMLBlock node from HTML string and optional attributes
|
|
123500
|
-
*/
|
|
123501
|
-
function createHTMLBlockNode(htmlString, position, runScripts, safeMode) {
|
|
123502
|
-
return {
|
|
123503
|
-
position,
|
|
123504
|
-
children: [{ type: 'text', value: htmlString }],
|
|
123505
|
-
type: NodeTypes.htmlBlock,
|
|
123506
|
-
data: {
|
|
123507
|
-
hName: 'html-block',
|
|
123508
|
-
hProperties: {
|
|
123509
|
-
html: htmlString,
|
|
123510
|
-
...(runScripts !== undefined && { runScripts }),
|
|
123511
|
-
...(safeMode !== undefined && { safeMode }),
|
|
123512
|
-
},
|
|
123513
|
-
},
|
|
123514
|
-
};
|
|
123515
|
-
}
|
|
123516
|
-
/**
|
|
123517
|
-
* Checks for opening tag only (for split detection)
|
|
123518
|
-
*/
|
|
123519
|
-
function hasOpeningTagOnly(node) {
|
|
123520
|
-
let hasOpening = false;
|
|
123521
|
-
let hasClosed = false;
|
|
123522
|
-
let attrs = '';
|
|
123523
|
-
const check = (n) => {
|
|
123524
|
-
if (n.type === 'html' && n.value) {
|
|
123525
|
-
if (n.value === '<HTMLBlock>') {
|
|
123526
|
-
hasOpening = true;
|
|
123527
|
-
}
|
|
123528
|
-
else {
|
|
123529
|
-
const match = n.value.match(/^<HTMLBlock(\s[^>]*)?>$/);
|
|
123530
|
-
if (match) {
|
|
123531
|
-
hasOpening = true;
|
|
123532
|
-
attrs = match[1] || '';
|
|
123533
|
-
}
|
|
123534
|
-
}
|
|
123535
|
-
if (n.value === '</HTMLBlock>' || n.value.includes('</HTMLBlock>')) {
|
|
123536
|
-
hasClosed = true;
|
|
123537
|
-
}
|
|
123538
|
-
}
|
|
123539
|
-
if (n.children && Array.isArray(n.children)) {
|
|
123540
|
-
n.children.forEach(child => {
|
|
123541
|
-
check(child);
|
|
123542
|
-
});
|
|
123543
|
-
}
|
|
123544
|
-
};
|
|
123545
|
-
check(node);
|
|
123546
|
-
// Return true only if opening without closing (split case)
|
|
123547
|
-
return { attrs, found: hasOpening && !hasClosed };
|
|
123548
|
-
}
|
|
123549
|
-
/**
|
|
123550
|
-
* Checks if a node contains an HTMLBlock closing tag
|
|
123551
|
-
*/
|
|
123552
|
-
function hasClosingTag(node) {
|
|
123553
|
-
if (node.type === 'html' && node.value) {
|
|
123554
|
-
if (node.value === '</HTMLBlock>' || node.value.includes('</HTMLBlock>'))
|
|
123555
|
-
return true;
|
|
123556
|
-
}
|
|
123557
|
-
if (node.children && Array.isArray(node.children)) {
|
|
123558
|
-
return node.children.some(child => hasClosingTag(child));
|
|
123559
|
-
}
|
|
123560
|
-
return false;
|
|
123561
|
-
}
|
|
123562
|
-
/**
|
|
123563
|
-
* Transforms HTMLBlock MDX JSX to html-block nodes. Handles <HTMLBlock>{`...`}</HTMLBlock> syntax.
|
|
123350
|
+
* Runs *after* `mdxishTables` so table cells are re-parsed first;
|
|
123351
|
+
* `mdxishTables` recognizes the still-JSX `<HTMLBlock>` element when deciding to
|
|
123352
|
+
* keep a table as a JSX `<Table>`. This replaces the old base64-comment marker
|
|
123353
|
+
* machinery — the #1455 tokenizer hands the body over already parsed.
|
|
123564
123354
|
*/
|
|
123565
123355
|
const mdxishHtmlBlocks = () => tree => {
|
|
123566
|
-
//
|
|
123567
|
-
visit(tree, '
|
|
123568
|
-
const
|
|
123569
|
-
|
|
123570
|
-
|
|
123571
|
-
|
|
123572
|
-
|
|
123573
|
-
|
|
123574
|
-
// Find closing tag in subsequent siblings
|
|
123575
|
-
let closingIdx = -1;
|
|
123576
|
-
for (let j = i + 1; j < children.length; j += 1) {
|
|
123577
|
-
if (hasClosingTag(children[j])) {
|
|
123578
|
-
closingIdx = j;
|
|
123579
|
-
break;
|
|
123580
|
-
}
|
|
123581
|
-
}
|
|
123582
|
-
if (closingIdx !== -1) {
|
|
123583
|
-
// Collect inner content between tags
|
|
123584
|
-
const contentParts = [];
|
|
123585
|
-
for (let j = i; j <= closingIdx; j += 1) {
|
|
123586
|
-
const node = children[j];
|
|
123587
|
-
contentParts.push(collectTextContent(node));
|
|
123588
|
-
}
|
|
123589
|
-
// Remove the opening/closing tags and template literal syntax from content
|
|
123590
|
-
let content = contentParts.join('');
|
|
123591
|
-
content = content.replace(/^<HTMLBlock[^>]*>\s*\{?\s*`?/, '').replace(/`?\s*\}?\s*<\/HTMLBlock>$/, '');
|
|
123592
|
-
// Decode protected content that was base64 encoded during preprocessing
|
|
123593
|
-
content = decodeProtectedContent(content);
|
|
123594
|
-
const htmlString = formatHtmlForMdxish(content);
|
|
123595
|
-
const runScripts = extractRunScriptsAttr(attrs);
|
|
123596
|
-
const safeMode = extractBooleanAttr(attrs, 'safeMode');
|
|
123597
|
-
// Replace range with single HTMLBlock node
|
|
123598
|
-
const mdNode = createHTMLBlockNode(htmlString, children[i].position, runScripts, safeMode);
|
|
123599
|
-
root.children.splice(i, closingIdx - i + 1, mdNode);
|
|
123600
|
-
}
|
|
123601
|
-
}
|
|
123602
|
-
i += 1;
|
|
123603
|
-
}
|
|
123356
|
+
// Shape 1: tokenized JSX element.
|
|
123357
|
+
visit(tree, node => node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement', (node, index, parent) => {
|
|
123358
|
+
const element = node;
|
|
123359
|
+
if (element.name !== 'HTMLBlock' || !parent || index === undefined)
|
|
123360
|
+
return;
|
|
123361
|
+
const exprChild = element.children.find(child => child.type === 'mdxFlowExpression' || child.type === 'mdxTextExpression');
|
|
123362
|
+
const openingTagIndent = (element.position?.start.column ?? 1) - 1;
|
|
123363
|
+
parent.children[index] = createHtmlBlockNode(formatHtmlForMdxish(extractTemplateLiteral(exprChild?.value), openingTagIndent), element.position, toRunScripts(jsxAttr(element, 'runScripts')), jsxAttr(element, 'safeMode'));
|
|
123604
123364
|
});
|
|
123605
|
-
//
|
|
123365
|
+
// Shape 2: raw HTML blob.
|
|
123606
123366
|
visit(tree, 'html', (node, index, parent) => {
|
|
123607
123367
|
if (!parent || index === undefined)
|
|
123608
123368
|
return;
|
|
123609
|
-
const
|
|
123610
|
-
if (
|
|
123611
|
-
|
|
123612
|
-
// Case 1: Full HTMLBlock in single node
|
|
123613
|
-
const fullMatch = value.match(/^<HTMLBlock(\s[^>]*)?>([\s\S]*)<\/HTMLBlock>$/);
|
|
123614
|
-
if (fullMatch) {
|
|
123615
|
-
const attrs = fullMatch[1] || '';
|
|
123616
|
-
let content = fullMatch[2] || '';
|
|
123617
|
-
// Remove template literal syntax if present: {`...`}
|
|
123618
|
-
content = content.replace(/^\s*\{\s*`/, '').replace(/`\s*\}\s*$/, '');
|
|
123619
|
-
// Decode protected content that was base64 encoded during preprocessing
|
|
123620
|
-
content = decodeProtectedContent(content);
|
|
123621
|
-
const htmlString = formatHtmlForMdxish(content);
|
|
123622
|
-
const runScripts = extractRunScriptsAttr(attrs);
|
|
123623
|
-
const safeMode = extractBooleanAttr(attrs, 'safeMode');
|
|
123624
|
-
parent.children[index] = createHTMLBlockNode(htmlString, node.position, runScripts, safeMode);
|
|
123625
|
-
return;
|
|
123626
|
-
}
|
|
123627
|
-
// Case 2: Opening tag only (split by blank lines)
|
|
123628
|
-
if (value === '<HTMLBlock>' || value.match(/^<HTMLBlock\s[^>]*>$/)) {
|
|
123629
|
-
const siblings = parent.children;
|
|
123630
|
-
let closingIdx = -1;
|
|
123631
|
-
// Find closing tag in siblings
|
|
123632
|
-
for (let i = index + 1; i < siblings.length; i += 1) {
|
|
123633
|
-
const sibling = siblings[i];
|
|
123634
|
-
if (sibling.type === 'html') {
|
|
123635
|
-
const sibVal = sibling.value;
|
|
123636
|
-
if (sibVal === '</HTMLBlock>' || sibVal?.includes('</HTMLBlock>')) {
|
|
123637
|
-
closingIdx = i;
|
|
123638
|
-
break;
|
|
123639
|
-
}
|
|
123640
|
-
}
|
|
123641
|
-
}
|
|
123642
|
-
if (closingIdx === -1)
|
|
123643
|
-
return;
|
|
123644
|
-
// Collect content between tags, skipping template literal delimiters
|
|
123645
|
-
const contentParts = [];
|
|
123646
|
-
for (let i = index + 1; i < closingIdx; i += 1) {
|
|
123647
|
-
const sibling = siblings[i];
|
|
123648
|
-
// Skip template literal delimiters
|
|
123649
|
-
if (sibling.type === 'text') {
|
|
123650
|
-
const textVal = sibling.value;
|
|
123651
|
-
if (textVal === '{' || textVal === '}' || textVal === '{`' || textVal === '`}') {
|
|
123652
|
-
// eslint-disable-next-line no-continue
|
|
123653
|
-
continue;
|
|
123654
|
-
}
|
|
123655
|
-
}
|
|
123656
|
-
contentParts.push(collectTextContent(sibling));
|
|
123657
|
-
}
|
|
123658
|
-
// Decode protected content that was base64 encoded during preprocessing
|
|
123659
|
-
const decodedContent = decodeProtectedContent(contentParts.join(''));
|
|
123660
|
-
const htmlString = formatHtmlForMdxish(decodedContent);
|
|
123661
|
-
const runScripts = extractRunScriptsAttr(value);
|
|
123662
|
-
const safeMode = extractBooleanAttr(value, 'safeMode');
|
|
123663
|
-
// Replace opening tag with HTMLBlock node, remove consumed siblings
|
|
123664
|
-
parent.children[index] = createHTMLBlockNode(htmlString, node.position, runScripts, safeMode);
|
|
123665
|
-
parent.children.splice(index + 1, closingIdx - index);
|
|
123666
|
-
}
|
|
123369
|
+
const replacement = splitRawHtmlBlocks(node);
|
|
123370
|
+
if (replacement)
|
|
123371
|
+
parent.children.splice(index, 1, ...replacement);
|
|
123667
123372
|
});
|
|
123668
|
-
//
|
|
123669
|
-
|
|
123670
|
-
|
|
123671
|
-
|
|
123672
|
-
|
|
123673
|
-
|
|
123674
|
-
let htmlBlockEndIdx = -1;
|
|
123675
|
-
let templateLiteralStartIdx = -1;
|
|
123676
|
-
let templateLiteralEndIdx = -1;
|
|
123373
|
+
// Shape 3: inline within a paragraph — `<HTMLBlock>` open/close arrive as
|
|
123374
|
+
// separate `html` siblings with the template-literal expression between them.
|
|
123375
|
+
visit(tree, 'paragraph', (paragraph) => {
|
|
123376
|
+
// An html-block is block content, so it isn't a valid PhrasingContent child;
|
|
123377
|
+
// widen to RootContent (which HTMLBlock belongs to) for the in-place splice.
|
|
123378
|
+
const children = paragraph.children;
|
|
123677
123379
|
for (let i = 0; i < children.length; i += 1) {
|
|
123678
|
-
const
|
|
123679
|
-
|
|
123680
|
-
|
|
123681
|
-
|
|
123682
|
-
|
|
123683
|
-
|
|
123684
|
-
|
|
123685
|
-
|
|
123686
|
-
|
|
123687
|
-
|
|
123688
|
-
|
|
123689
|
-
|
|
123690
|
-
const value = child.value;
|
|
123691
|
-
if (value === '{') {
|
|
123692
|
-
templateLiteralStartIdx = i;
|
|
123380
|
+
const open = children[i];
|
|
123381
|
+
const openMatch = open.type === 'html' ? open.value.match(HTML_BLOCK_OPEN_RE) : null;
|
|
123382
|
+
if (!openMatch)
|
|
123383
|
+
continue; // eslint-disable-line no-continue
|
|
123384
|
+
const closeIdx = children.findIndex((child, j) => j > i && child.type === 'html' && child.value === '</HTMLBlock>');
|
|
123385
|
+
if (closeIdx === -1)
|
|
123386
|
+
continue; // eslint-disable-line no-continue
|
|
123387
|
+
const body = children
|
|
123388
|
+
.slice(i + 1, closeIdx)
|
|
123389
|
+
.map(child => {
|
|
123390
|
+
if (child.type === 'mdxTextExpression' || child.type === 'mdxFlowExpression') {
|
|
123391
|
+
return extractTemplateLiteral(child.value);
|
|
123693
123392
|
}
|
|
123694
|
-
|
|
123695
|
-
|
|
123696
|
-
|
|
123697
|
-
|
|
123698
|
-
|
|
123699
|
-
|
|
123700
|
-
|
|
123701
|
-
|
|
123702
|
-
}
|
|
123703
|
-
if (htmlBlockStartIdx !== -1 &&
|
|
123704
|
-
htmlBlockEndIdx !== -1 &&
|
|
123705
|
-
templateLiteralStartIdx !== -1 &&
|
|
123706
|
-
templateLiteralEndIdx !== -1 &&
|
|
123707
|
-
templateLiteralStartIdx < templateLiteralEndIdx) {
|
|
123708
|
-
const openingTag = children[htmlBlockStartIdx];
|
|
123709
|
-
// Collect content between braces (handles code blocks)
|
|
123710
|
-
const templateContent = [];
|
|
123711
|
-
for (let i = templateLiteralStartIdx + 1; i < templateLiteralEndIdx; i += 1) {
|
|
123712
|
-
const child = children[i];
|
|
123713
|
-
templateContent.push(collectTextContent(child));
|
|
123714
|
-
}
|
|
123715
|
-
// Decode protected content that was base64 encoded during preprocessing
|
|
123716
|
-
const decodedContent = decodeProtectedContent(templateContent.join(''));
|
|
123717
|
-
const htmlString = formatHtmlForMdxish(decodedContent);
|
|
123718
|
-
const runScripts = openingTag.value ? extractRunScriptsAttr(openingTag.value) : undefined;
|
|
123719
|
-
const safeMode = openingTag.value ? extractBooleanAttr(openingTag.value, 'safeMode') : undefined;
|
|
123720
|
-
const mdNode = createHTMLBlockNode(htmlString, node.position, runScripts, safeMode);
|
|
123721
|
-
parent.children[index] = mdNode;
|
|
123722
|
-
}
|
|
123723
|
-
});
|
|
123724
|
-
// Ensure html-block nodes have HTML in children as text node
|
|
123725
|
-
visit(tree, 'html-block', (node) => {
|
|
123726
|
-
const html = node.data?.hProperties?.html;
|
|
123727
|
-
if (html &&
|
|
123728
|
-
(!node.children ||
|
|
123729
|
-
node.children.length === 0 ||
|
|
123730
|
-
(node.children.length === 1 && node.children[0].type === 'text' && node.children[0].value !== html))) {
|
|
123731
|
-
node.children = [
|
|
123732
|
-
{
|
|
123733
|
-
type: 'text',
|
|
123734
|
-
value: html,
|
|
123735
|
-
},
|
|
123736
|
-
];
|
|
123393
|
+
// Preserve raw text from any other phrasing sibling (e.g. stray
|
|
123394
|
+
// whitespace or content the tokenizer didn't claim) so it isn't
|
|
123395
|
+
// silently dropped from the html payload.
|
|
123396
|
+
return 'value' in child && typeof child.value === 'string' ? child.value : '';
|
|
123397
|
+
})
|
|
123398
|
+
.join('');
|
|
123399
|
+
const openingTagIndent = (open.position?.start.column ?? 1) - 1;
|
|
123400
|
+
children.splice(i, closeIdx - i + 1, htmlBlockFromRaw(openMatch[1], body, open.position, openingTagIndent));
|
|
123737
123401
|
}
|
|
123738
123402
|
});
|
|
123739
|
-
return tree;
|
|
123740
123403
|
};
|
|
123741
123404
|
/* harmony default export */ const mdxish_html_blocks = (mdxishHtmlBlocks);
|
|
123742
123405
|
|
|
@@ -124517,6 +124180,189 @@ const normalizeMdxJsxNodes = () => tree => {
|
|
|
124517
124180
|
};
|
|
124518
124181
|
/* harmony default export */ const normalize_mdx_jsx_nodes = (normalizeMdxJsxNodes);
|
|
124519
124182
|
|
|
124183
|
+
;// ./lib/micromark/jsx-comment/pattern.ts
|
|
124184
|
+
/**
|
|
124185
|
+
* Matches a JSX comment: `{/*`, content, `*\/}` — no whitespace tolerated
|
|
124186
|
+
* between the braces and the comment markers.
|
|
124187
|
+
*
|
|
124188
|
+
* This grammar is mirrored by the flow tokenizer in ./syntax.ts. Any change
|
|
124189
|
+
* here needs a mirror change in the state machine; the parity test in
|
|
124190
|
+
* __tests__/lib/micromark/jsx-comment-pattern-parity.test.ts locks the two
|
|
124191
|
+
* together so they can't silently drift.
|
|
124192
|
+
*/
|
|
124193
|
+
const JSX_COMMENT_REGEX = /\{\/\*[^*]*(?:\*(?!\/)[^*]*)*\*\/\}/g;
|
|
124194
|
+
|
|
124195
|
+
;// ./processor/transform/mdxish/preprocess-jsx-expressions.ts
|
|
124196
|
+
|
|
124197
|
+
|
|
124198
|
+
/**
|
|
124199
|
+
* Removes JSX-style comments (e.g., { /* comment *\/ }) from content.
|
|
124200
|
+
*
|
|
124201
|
+
* @param content
|
|
124202
|
+
* @returns Content with JSX comments removed
|
|
124203
|
+
* @example
|
|
124204
|
+
* ```typescript
|
|
124205
|
+
* removeJSXComments('Text { /* comment *\/ } more text')
|
|
124206
|
+
* // Returns: 'Text more text'
|
|
124207
|
+
* ```
|
|
124208
|
+
*/
|
|
124209
|
+
function removeJSXComments(content) {
|
|
124210
|
+
return content.replace(JSX_COMMENT_REGEX, '');
|
|
124211
|
+
}
|
|
124212
|
+
const HTML_ELEM_PLACEHOLDER_PREFIX = '___MDXISH_HTML_ELEM_';
|
|
124213
|
+
const HTML_ELEM_PLACEHOLDER = new RegExp(`${HTML_ELEM_PLACEHOLDER_PREFIX}(\\d+)___`, 'g');
|
|
124214
|
+
// Matches an HTML element that starts at a line boundary and ends at a line boundary.
|
|
124215
|
+
// Allows optional leading indentation and lazily matches until the same closing tag.
|
|
124216
|
+
const BLOCK_HTML_RE = /(?<=^|\n)[ \t]*<([a-z][a-zA-Z0-9]*)(?:\s[^>]*)?>[\s\S]*?<\/\1>[ \t]*(?=\n|$)/g;
|
|
124217
|
+
/**
|
|
124218
|
+
* Hides line-anchored HTML elements from the brace-escaping pass so we don't leak `\{`
|
|
124219
|
+
* into rendered output (rehypeRaw renders the `\` literally, e.g. `<div>{foo</div>`).
|
|
124220
|
+
*
|
|
124221
|
+
* One carve-out: if an interior line at column 0 has bare text containing `{`, mdxish
|
|
124222
|
+
* parses that line as a paragraph and the mdxExpression step would throw without an
|
|
124223
|
+
* escape — so we leave that case to the brace balancer.
|
|
124224
|
+
*/
|
|
124225
|
+
function protectHTMLElements(content) {
|
|
124226
|
+
const htmlElements = [];
|
|
124227
|
+
const protectedContent = content.replace(BLOCK_HTML_RE, match => {
|
|
124228
|
+
// Look at the lines between the open and close tags. If any of them starts
|
|
124229
|
+
// at column 0 with bare text (not whitespace, not another tag) and contains
|
|
124230
|
+
// `{`, mdxish will parse that line as a paragraph and the brace as an MDX
|
|
124231
|
+
// expression, which would throw an error. So we let the brace balancer escape it.
|
|
124232
|
+
// Otherwise, we need to extract the sequence to protect it from the brace escaping.
|
|
124233
|
+
const interior = match.split('\n').slice(1, -1);
|
|
124234
|
+
const hazard = interior.some(line => line.length > 0 && line[0] !== ' ' && line[0] !== '\t' && line[0] !== '<' && line.includes('{'));
|
|
124235
|
+
if (hazard)
|
|
124236
|
+
return match;
|
|
124237
|
+
htmlElements.push(match);
|
|
124238
|
+
return `${HTML_ELEM_PLACEHOLDER_PREFIX}${htmlElements.length - 1}___`;
|
|
124239
|
+
});
|
|
124240
|
+
return { htmlElements, protectedContent };
|
|
124241
|
+
}
|
|
124242
|
+
function restoreHTMLElements(content, htmlElements) {
|
|
124243
|
+
if (htmlElements.length === 0)
|
|
124244
|
+
return content;
|
|
124245
|
+
return content.replace(HTML_ELEM_PLACEHOLDER, (_m, idx) => htmlElements[parseInt(idx, 10)]);
|
|
124246
|
+
}
|
|
124247
|
+
/**
|
|
124248
|
+
* Escapes unbalanced and paragraph-spanning braces so MDX doesn't trip on them.
|
|
124249
|
+
*/
|
|
124250
|
+
function escapeProblematicBraces(content) {
|
|
124251
|
+
const { htmlElements, protectedContent } = protectHTMLElements(content);
|
|
124252
|
+
let strDelim = null;
|
|
124253
|
+
let strEscaped = false;
|
|
124254
|
+
// Track position of last newline (outside strings) to detect blank lines
|
|
124255
|
+
// -2 means no recent newline
|
|
124256
|
+
let lastNewlinePos = -2;
|
|
124257
|
+
// Character state machine trackers
|
|
124258
|
+
const toEscape = new Set();
|
|
124259
|
+
// Convert to array of Unicode code points so that emojis and multi-byte characters are correctly tracked
|
|
124260
|
+
const chars = Array.from(protectedContent);
|
|
124261
|
+
const openStack = [];
|
|
124262
|
+
for (let i = 0; i < chars.length; i += 1) {
|
|
124263
|
+
const ch = chars[i];
|
|
124264
|
+
// Track string delimiters inside expressions to ignore braces within them
|
|
124265
|
+
if (openStack.length > 0) {
|
|
124266
|
+
if (strDelim) {
|
|
124267
|
+
if (strEscaped)
|
|
124268
|
+
strEscaped = false;
|
|
124269
|
+
else if (ch === '\\')
|
|
124270
|
+
strEscaped = true;
|
|
124271
|
+
else if (ch === strDelim)
|
|
124272
|
+
strDelim = null;
|
|
124273
|
+
// eslint-disable-next-line no-continue
|
|
124274
|
+
continue;
|
|
124275
|
+
}
|
|
124276
|
+
if (ch === '"' || ch === "'" || ch === '`') {
|
|
124277
|
+
strDelim = ch;
|
|
124278
|
+
// eslint-disable-next-line no-continue
|
|
124279
|
+
continue;
|
|
124280
|
+
}
|
|
124281
|
+
if (ch === '\n') {
|
|
124282
|
+
if (lastNewlinePos >= 0) {
|
|
124283
|
+
const between = chars.slice(lastNewlinePos + 1, i).join('');
|
|
124284
|
+
if (/^[ \t]*$/.test(between)) {
|
|
124285
|
+
openStack.forEach(entry => { entry.hasBlankLine = true; });
|
|
124286
|
+
}
|
|
124287
|
+
}
|
|
124288
|
+
lastNewlinePos = i;
|
|
124289
|
+
}
|
|
124290
|
+
}
|
|
124291
|
+
// Skip already-escaped braces (odd run of preceding backslashes).
|
|
124292
|
+
if (ch === '{' || ch === '}') {
|
|
124293
|
+
let bs = 0;
|
|
124294
|
+
for (let j = i - 1; j >= 0 && chars[j] === '\\'; j -= 1)
|
|
124295
|
+
bs += 1;
|
|
124296
|
+
if (bs % 2 === 1) {
|
|
124297
|
+
// eslint-disable-next-line no-continue
|
|
124298
|
+
continue;
|
|
124299
|
+
}
|
|
124300
|
+
}
|
|
124301
|
+
if (ch === '{') {
|
|
124302
|
+
// `=` (after whitespace) before `{` ⇒ JSX attribute expression. The
|
|
124303
|
+
// mdxComponent tokenizer captures the whole component, so blank lines
|
|
124304
|
+
// inside attribute values are harmless. Nested `{` inherits the flag.
|
|
124305
|
+
let isAttrExpr = false;
|
|
124306
|
+
for (let j = i - 1; j >= 0; j -= 1) {
|
|
124307
|
+
const pc = chars[j];
|
|
124308
|
+
if (pc === '=') {
|
|
124309
|
+
isAttrExpr = true;
|
|
124310
|
+
break;
|
|
124311
|
+
}
|
|
124312
|
+
if (pc !== ' ' && pc !== '\t')
|
|
124313
|
+
break;
|
|
124314
|
+
}
|
|
124315
|
+
// Nested `{ ... }` inside an attribute value (e.g. `data={[{ ... }]}` or
|
|
124316
|
+
// `data={{ a: { b: 1 } }}`) must inherit the same exemption; only the
|
|
124317
|
+
// outer `{` is directly after `=`.
|
|
124318
|
+
if (!isAttrExpr && openStack.length > 0 && openStack[openStack.length - 1].isAttrExpr) {
|
|
124319
|
+
isAttrExpr = true;
|
|
124320
|
+
}
|
|
124321
|
+
openStack.push({ pos: i, hasBlankLine: false, isAttrExpr });
|
|
124322
|
+
lastNewlinePos = -2;
|
|
124323
|
+
}
|
|
124324
|
+
else if (ch === '}') {
|
|
124325
|
+
if (openStack.length > 0) {
|
|
124326
|
+
const entry = openStack.pop();
|
|
124327
|
+
// Pure `{/* ... */}` comments are handled downstream by the jsxComment
|
|
124328
|
+
// tokenizer — escaping their braces would prevent it from running.
|
|
124329
|
+
const isPureJsxComment = chars[entry.pos + 1] === '/' &&
|
|
124330
|
+
chars[entry.pos + 2] === '*' &&
|
|
124331
|
+
chars[i - 1] === '/' &&
|
|
124332
|
+
chars[i - 2] === '*';
|
|
124333
|
+
if (entry.hasBlankLine && !isPureJsxComment && !entry.isAttrExpr) {
|
|
124334
|
+
toEscape.add(entry.pos);
|
|
124335
|
+
toEscape.add(i);
|
|
124336
|
+
}
|
|
124337
|
+
}
|
|
124338
|
+
else {
|
|
124339
|
+
toEscape.add(i);
|
|
124340
|
+
}
|
|
124341
|
+
}
|
|
124342
|
+
}
|
|
124343
|
+
// Anything still open is unbalanced.
|
|
124344
|
+
openStack.forEach(entry => toEscape.add(entry.pos));
|
|
124345
|
+
// Reconstruct the content with the escaped braces.
|
|
124346
|
+
const escapedContent = toEscape.size === 0 ? protectedContent : chars.map((ch, i) => (toEscape.has(i) ? `\\${ch}` : ch)).join('');
|
|
124347
|
+
return restoreHTMLElements(escapedContent, htmlElements);
|
|
124348
|
+
}
|
|
124349
|
+
/**
|
|
124350
|
+
* Preprocesses JSX-like markdown content before parsing.
|
|
124351
|
+
*
|
|
124352
|
+
* JSX attribute expressions (`href={baseUrl}`) are no longer rewritten here —
|
|
124353
|
+
* they flow through the tokenizer as `mdxJsxAttributeValueExpression` nodes
|
|
124354
|
+
* and are evaluated at the hast handler step.
|
|
124355
|
+
*
|
|
124356
|
+
* @param content
|
|
124357
|
+
* @returns Preprocessed content ready for markdown parsing
|
|
124358
|
+
*/
|
|
124359
|
+
function preprocessJSXExpressions(content) {
|
|
124360
|
+
const { protectedCode, protectedContent } = protectCodeBlocks(content);
|
|
124361
|
+
let processed = escapeProblematicBraces(protectedContent);
|
|
124362
|
+
processed = restoreCodeBlocks(processed, protectedCode);
|
|
124363
|
+
return processed;
|
|
124364
|
+
}
|
|
124365
|
+
|
|
124520
124366
|
;// ./processor/transform/mdxish/restore-snake-case-component-name.ts
|
|
124521
124367
|
|
|
124522
124368
|
|
|
@@ -125633,7 +125479,7 @@ function mdxishAstProcessor(mdContent, opts = {}) {
|
|
|
125633
125479
|
.use(inline_html, { safeMode })
|
|
125634
125480
|
.use(restore_snake_case_component_name, { mapping: snakeCaseMapping })
|
|
125635
125481
|
.use(mdxish_tables)
|
|
125636
|
-
.use(mdxish_html_blocks)
|
|
125482
|
+
.use(mdxish_html_blocks) // Convert every <HTMLBlock> shape → html-block
|
|
125637
125483
|
// The next few transformers must appear after mdxishMdxComponentBlocks
|
|
125638
125484
|
// so nodes produced by the inline re-parse of component bodies
|
|
125639
125485
|
// (e.g. code/image/embed inside <Tabs>) get visited too
|