@readme/markdown 14.6.0 → 14.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +373 -547
- package/dist/main.node.js +371 -545
- 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))
|
|
@@ -121095,7 +121137,7 @@ function createTokenize(mode) {
|
|
|
121095
121137
|
return tagNameRest;
|
|
121096
121138
|
}
|
|
121097
121139
|
// Tag name complete — check exclusions
|
|
121098
|
-
if (
|
|
121140
|
+
if (TOKENIZER_MDX_COMPONENT_EXCLUDED_TAGS.has(tagName)) {
|
|
121099
121141
|
return nok(code);
|
|
121100
121142
|
}
|
|
121101
121143
|
depth = 1;
|
|
@@ -123186,557 +123228,158 @@ const magicBlockTransformer = (options = {}) => tree => {
|
|
|
123186
123228
|
};
|
|
123187
123229
|
/* harmony default export */ const magic_block_transformer = (magicBlockTransformer);
|
|
123188
123230
|
|
|
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;
|
|
123231
|
+
;// ./processor/transform/mdxish/mdxish-html-blocks.ts
|
|
123200
123232
|
|
|
123201
|
-
;// ./processor/transform/mdxish/preprocess-jsx-expressions.ts
|
|
123202
123233
|
|
|
123203
123234
|
|
|
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-->';
|
|
123235
|
+
// `<HTMLBlock …>{`…`}</HTMLBlock>` embedded inside a raw HTML block (e.g. a
|
|
123236
|
+
// single-line `<div>…</div>`). CommonMark slurps the whole div as one `html`
|
|
123237
|
+
// node, so the tokenizer never sees the HTMLBlock — we recover it here.
|
|
123238
|
+
const RAW_HTML_BLOCK_RE = /<HTMLBlock\b([^>]*)>\s*\{\s*`((?:[^`\\]|\\.)*)`\s*\}\s*<\/HTMLBlock>/g;
|
|
123239
|
+
// Opening `<HTMLBlock …>` as its own `html` node — produced inside a paragraph
|
|
123240
|
+
// when an HTMLBlock appears inline alongside text.
|
|
123241
|
+
const HTML_BLOCK_OPEN_RE = /^<HTMLBlock\b([^>]*)>$/;
|
|
123221
123242
|
/**
|
|
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
|
-
* ```
|
|
123243
|
+
* Builds the canonical `html-block` MDAST node the renderer expects.
|
|
123232
123244
|
*/
|
|
123233
|
-
|
|
123234
|
-
|
|
123235
|
-
|
|
123236
|
-
|
|
123237
|
-
|
|
123238
|
-
|
|
123245
|
+
const createHtmlBlockNode = (html, position, runScripts, safeMode) => ({
|
|
123246
|
+
position,
|
|
123247
|
+
children: [{ type: 'text', value: html }],
|
|
123248
|
+
type: NodeTypes.htmlBlock,
|
|
123249
|
+
data: {
|
|
123250
|
+
hName: 'html-block',
|
|
123251
|
+
hProperties: {
|
|
123252
|
+
html,
|
|
123253
|
+
...(runScripts !== undefined && { runScripts }),
|
|
123254
|
+
...(safeMode !== undefined && { safeMode }),
|
|
123255
|
+
},
|
|
123256
|
+
},
|
|
123257
|
+
});
|
|
123239
123258
|
/**
|
|
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
|
-
* ```
|
|
123259
|
+
* Reads the cooked string out of a brace expression wrapping a single template
|
|
123260
|
+
* literal (`` `<p>n</p>` `` → `<p>n</p>`).
|
|
123249
123261
|
*/
|
|
123250
|
-
|
|
123251
|
-
|
|
123252
|
-
|
|
123253
|
-
const
|
|
123254
|
-
|
|
123255
|
-
//
|
|
123256
|
-
|
|
123257
|
-
|
|
123262
|
+
const extractTemplateLiteral = (value) => {
|
|
123263
|
+
if (!value)
|
|
123264
|
+
return '';
|
|
123265
|
+
const match = value.trim().match(/^`([\s\S]*)`$/);
|
|
123266
|
+
// Non-template-literal bodies (e.g. `{someVar}`) are malformed mdxish input;
|
|
123267
|
+
// returning '' beats shipping JS identifier source as an HTML payload.
|
|
123268
|
+
return match ? match[1] : '';
|
|
123269
|
+
};
|
|
123270
|
+
const toRunScripts = (raw) => raw === 'true' ? true : raw === 'false' ? false : raw;
|
|
123271
|
+
/** Reads an attribute from a raw `<HTMLBlock …>` attribute string. */
|
|
123272
|
+
const rawAttr = (attrs, name) => {
|
|
123273
|
+
const quoted = attrs.match(new RegExp(`\\b${name}\\s*=\\s*"([^"]*)"`));
|
|
123274
|
+
if (quoted)
|
|
123275
|
+
return quoted[1];
|
|
123276
|
+
const expr = attrs.match(new RegExp(`\\b${name}\\s*=\\s*\\{(true|false)\\}`));
|
|
123277
|
+
if (expr)
|
|
123278
|
+
return expr[1];
|
|
123279
|
+
return new RegExp(`\\b${name}\\b`).test(attrs) ? 'true' : undefined;
|
|
123280
|
+
};
|
|
123281
|
+
/** Reads an attribute from a parsed `<HTMLBlock>` JSX element. */
|
|
123282
|
+
const jsxAttr = (element, name) => {
|
|
123283
|
+
const attr = element.attributes.find(a => a.type === 'mdxJsxAttribute' && a.name === name);
|
|
123284
|
+
if (!attr || attr.type !== 'mdxJsxAttribute')
|
|
123285
|
+
return undefined;
|
|
123286
|
+
if (typeof attr.value === 'string')
|
|
123287
|
+
return attr.value;
|
|
123288
|
+
if (attr.value && typeof attr.value === 'object' && 'value' in attr.value)
|
|
123289
|
+
return attr.value.value;
|
|
123290
|
+
return 'true'; // bare boolean attribute, e.g. <HTMLBlock runScripts />
|
|
123291
|
+
};
|
|
123292
|
+
/** Builds an `html-block` from a raw attribute string and (unparsed) body. */
|
|
123293
|
+
const htmlBlockFromRaw = (attrs, html, position, openingTagIndent = 0) => createHtmlBlockNode(formatHtmlForMdxish(html, openingTagIndent), position, toRunScripts(rawAttr(attrs, 'runScripts')), rawAttr(attrs, 'safeMode'));
|
|
123258
123294
|
/**
|
|
123259
|
-
*
|
|
123260
|
-
*
|
|
123295
|
+
* Splits a raw `html` node that embeds one or more `<HTMLBlock>`s into
|
|
123296
|
+
* `[html before, html-block, html after, …]`. Returns null when there is none.
|
|
123261
123297
|
*
|
|
123262
|
-
*
|
|
123263
|
-
*
|
|
123264
|
-
* escape — so we leave that case to the brace balancer.
|
|
123265
|
-
*/
|
|
123266
|
-
function protectHTMLElements(content) {
|
|
123267
|
-
const htmlElements = [];
|
|
123268
|
-
const protectedContent = content.replace(BLOCK_HTML_RE, match => {
|
|
123269
|
-
// Look at the lines between the open and close tags. If any of them starts
|
|
123270
|
-
// at column 0 with bare text (not whitespace, not another tag) and contains
|
|
123271
|
-
// `{`, mdxish will parse that line as a paragraph and the brace as an MDX
|
|
123272
|
-
// expression, which would throw an error. So we let the brace balancer escape it.
|
|
123273
|
-
// Otherwise, we need to extract the sequence to protect it from the brace escaping.
|
|
123274
|
-
const interior = match.split('\n').slice(1, -1);
|
|
123275
|
-
const hazard = interior.some(line => line.length > 0 && line[0] !== ' ' && line[0] !== '\t' && line[0] !== '<' && line.includes('{'));
|
|
123276
|
-
if (hazard)
|
|
123277
|
-
return match;
|
|
123278
|
-
htmlElements.push(match);
|
|
123279
|
-
return `${HTML_ELEM_PLACEHOLDER_PREFIX}${htmlElements.length - 1}___`;
|
|
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.
|
|
123298
|
+
* `String.split` on a regex with capture groups interleaves the captures into
|
|
123299
|
+
* the result, so segments arrive as `[text, attrs, body, text, attrs, body, …]`.
|
|
123290
123300
|
*/
|
|
123291
|
-
|
|
123292
|
-
const
|
|
123293
|
-
|
|
123294
|
-
|
|
123295
|
-
|
|
123296
|
-
|
|
123297
|
-
|
|
123298
|
-
|
|
123299
|
-
|
|
123300
|
-
|
|
123301
|
-
|
|
123302
|
-
|
|
123303
|
-
|
|
123304
|
-
|
|
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
|
-
}
|
|
123301
|
+
const splitRawHtmlBlocks = (node) => {
|
|
123302
|
+
const segments = node.value.split(RAW_HTML_BLOCK_RE);
|
|
123303
|
+
if (segments.length === 1)
|
|
123304
|
+
return null; // no <HTMLBlock> present
|
|
123305
|
+
const parts = [];
|
|
123306
|
+
for (let i = 0; i < segments.length; i += 3) {
|
|
123307
|
+
const [text, attrs, body] = segments.slice(i, i + 3);
|
|
123308
|
+
if (text)
|
|
123309
|
+
parts.push({ type: 'html', value: text });
|
|
123310
|
+
if (body !== undefined) {
|
|
123311
|
+
// The opening tag's column equals the length of the line it starts on
|
|
123312
|
+
// (the text run since the previous newline preceding the match).
|
|
123313
|
+
const openingTagIndent = text.slice(text.lastIndexOf('\n') + 1).length;
|
|
123314
|
+
parts.push(htmlBlockFromRaw(attrs, body, node.position, openingTagIndent));
|
|
123382
123315
|
}
|
|
123383
123316
|
}
|
|
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
|
-
}
|
|
123317
|
+
return parts;
|
|
123318
|
+
};
|
|
123390
123319
|
/**
|
|
123391
|
-
*
|
|
123320
|
+
* Converts every `<HTMLBlock>` shape that survives parsing into the canonical
|
|
123321
|
+
* `html-block` MDAST node, reading the body from the tokenizer's template-literal
|
|
123322
|
+
* expression. Three shapes occur:
|
|
123392
123323
|
*
|
|
123393
|
-
* JSX
|
|
123394
|
-
*
|
|
123395
|
-
*
|
|
123324
|
+
* 1. JSX element (`mdxJsxFlowElement`/`mdxJsxTextElement`) — multiline/block
|
|
123325
|
+
* context and table cells (after their remarkMdx re-parse).
|
|
123326
|
+
* 2. Raw `html` blob (`splitRawHtmlBlocks`) — single-line top-level, or nested
|
|
123327
|
+
* in raw HTML like an inline `<div>`.
|
|
123328
|
+
* 3. Inline-in-paragraph — split into `html` + expression + `html` siblings.
|
|
123396
123329
|
*
|
|
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.
|
|
123330
|
+
* Runs *after* `mdxishTables` so table cells are re-parsed first;
|
|
123331
|
+
* `mdxishTables` recognizes the still-JSX `<HTMLBlock>` element when deciding to
|
|
123332
|
+
* keep a table as a JSX `<Table>`. This replaces the old base64-comment marker
|
|
123333
|
+
* machinery — the #1455 tokenizer hands the body over already parsed.
|
|
123564
123334
|
*/
|
|
123565
123335
|
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
|
-
}
|
|
123336
|
+
// Shape 1: tokenized JSX element.
|
|
123337
|
+
visit(tree, node => node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement', (node, index, parent) => {
|
|
123338
|
+
const element = node;
|
|
123339
|
+
if (element.name !== 'HTMLBlock' || !parent || index === undefined)
|
|
123340
|
+
return;
|
|
123341
|
+
const exprChild = element.children.find(child => child.type === 'mdxFlowExpression' || child.type === 'mdxTextExpression');
|
|
123342
|
+
const openingTagIndent = (element.position?.start.column ?? 1) - 1;
|
|
123343
|
+
parent.children[index] = createHtmlBlockNode(formatHtmlForMdxish(extractTemplateLiteral(exprChild?.value), openingTagIndent), element.position, toRunScripts(jsxAttr(element, 'runScripts')), jsxAttr(element, 'safeMode'));
|
|
123604
123344
|
});
|
|
123605
|
-
//
|
|
123345
|
+
// Shape 2: raw HTML blob.
|
|
123606
123346
|
visit(tree, 'html', (node, index, parent) => {
|
|
123607
123347
|
if (!parent || index === undefined)
|
|
123608
123348
|
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
|
-
}
|
|
123349
|
+
const replacement = splitRawHtmlBlocks(node);
|
|
123350
|
+
if (replacement)
|
|
123351
|
+
parent.children.splice(index, 1, ...replacement);
|
|
123667
123352
|
});
|
|
123668
|
-
//
|
|
123669
|
-
|
|
123670
|
-
|
|
123671
|
-
|
|
123672
|
-
|
|
123673
|
-
|
|
123674
|
-
let htmlBlockEndIdx = -1;
|
|
123675
|
-
let templateLiteralStartIdx = -1;
|
|
123676
|
-
let templateLiteralEndIdx = -1;
|
|
123353
|
+
// Shape 3: inline within a paragraph — `<HTMLBlock>` open/close arrive as
|
|
123354
|
+
// separate `html` siblings with the template-literal expression between them.
|
|
123355
|
+
visit(tree, 'paragraph', (paragraph) => {
|
|
123356
|
+
// An html-block is block content, so it isn't a valid PhrasingContent child;
|
|
123357
|
+
// widen to RootContent (which HTMLBlock belongs to) for the in-place splice.
|
|
123358
|
+
const children = paragraph.children;
|
|
123677
123359
|
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;
|
|
123360
|
+
const open = children[i];
|
|
123361
|
+
const openMatch = open.type === 'html' ? open.value.match(HTML_BLOCK_OPEN_RE) : null;
|
|
123362
|
+
if (!openMatch)
|
|
123363
|
+
continue; // eslint-disable-line no-continue
|
|
123364
|
+
const closeIdx = children.findIndex((child, j) => j > i && child.type === 'html' && child.value === '</HTMLBlock>');
|
|
123365
|
+
if (closeIdx === -1)
|
|
123366
|
+
continue; // eslint-disable-line no-continue
|
|
123367
|
+
const body = children
|
|
123368
|
+
.slice(i + 1, closeIdx)
|
|
123369
|
+
.map(child => {
|
|
123370
|
+
if (child.type === 'mdxTextExpression' || child.type === 'mdxFlowExpression') {
|
|
123371
|
+
return extractTemplateLiteral(child.value);
|
|
123693
123372
|
}
|
|
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
|
-
];
|
|
123373
|
+
// Preserve raw text from any other phrasing sibling (e.g. stray
|
|
123374
|
+
// whitespace or content the tokenizer didn't claim) so it isn't
|
|
123375
|
+
// silently dropped from the html payload.
|
|
123376
|
+
return 'value' in child && typeof child.value === 'string' ? child.value : '';
|
|
123377
|
+
})
|
|
123378
|
+
.join('');
|
|
123379
|
+
const openingTagIndent = (open.position?.start.column ?? 1) - 1;
|
|
123380
|
+
children.splice(i, closeIdx - i + 1, htmlBlockFromRaw(openMatch[1], body, open.position, openingTagIndent));
|
|
123737
123381
|
}
|
|
123738
123382
|
});
|
|
123739
|
-
return tree;
|
|
123740
123383
|
};
|
|
123741
123384
|
/* harmony default export */ const mdxish_html_blocks = (mdxishHtmlBlocks);
|
|
123742
123385
|
|
|
@@ -124517,6 +124160,189 @@ const normalizeMdxJsxNodes = () => tree => {
|
|
|
124517
124160
|
};
|
|
124518
124161
|
/* harmony default export */ const normalize_mdx_jsx_nodes = (normalizeMdxJsxNodes);
|
|
124519
124162
|
|
|
124163
|
+
;// ./lib/micromark/jsx-comment/pattern.ts
|
|
124164
|
+
/**
|
|
124165
|
+
* Matches a JSX comment: `{/*`, content, `*\/}` — no whitespace tolerated
|
|
124166
|
+
* between the braces and the comment markers.
|
|
124167
|
+
*
|
|
124168
|
+
* This grammar is mirrored by the flow tokenizer in ./syntax.ts. Any change
|
|
124169
|
+
* here needs a mirror change in the state machine; the parity test in
|
|
124170
|
+
* __tests__/lib/micromark/jsx-comment-pattern-parity.test.ts locks the two
|
|
124171
|
+
* together so they can't silently drift.
|
|
124172
|
+
*/
|
|
124173
|
+
const JSX_COMMENT_REGEX = /\{\/\*[^*]*(?:\*(?!\/)[^*]*)*\*\/\}/g;
|
|
124174
|
+
|
|
124175
|
+
;// ./processor/transform/mdxish/preprocess-jsx-expressions.ts
|
|
124176
|
+
|
|
124177
|
+
|
|
124178
|
+
/**
|
|
124179
|
+
* Removes JSX-style comments (e.g., { /* comment *\/ }) from content.
|
|
124180
|
+
*
|
|
124181
|
+
* @param content
|
|
124182
|
+
* @returns Content with JSX comments removed
|
|
124183
|
+
* @example
|
|
124184
|
+
* ```typescript
|
|
124185
|
+
* removeJSXComments('Text { /* comment *\/ } more text')
|
|
124186
|
+
* // Returns: 'Text more text'
|
|
124187
|
+
* ```
|
|
124188
|
+
*/
|
|
124189
|
+
function removeJSXComments(content) {
|
|
124190
|
+
return content.replace(JSX_COMMENT_REGEX, '');
|
|
124191
|
+
}
|
|
124192
|
+
const HTML_ELEM_PLACEHOLDER_PREFIX = '___MDXISH_HTML_ELEM_';
|
|
124193
|
+
const HTML_ELEM_PLACEHOLDER = new RegExp(`${HTML_ELEM_PLACEHOLDER_PREFIX}(\\d+)___`, 'g');
|
|
124194
|
+
// Matches an HTML element that starts at a line boundary and ends at a line boundary.
|
|
124195
|
+
// Allows optional leading indentation and lazily matches until the same closing tag.
|
|
124196
|
+
const BLOCK_HTML_RE = /(?<=^|\n)[ \t]*<([a-z][a-zA-Z0-9]*)(?:\s[^>]*)?>[\s\S]*?<\/\1>[ \t]*(?=\n|$)/g;
|
|
124197
|
+
/**
|
|
124198
|
+
* Hides line-anchored HTML elements from the brace-escaping pass so we don't leak `\{`
|
|
124199
|
+
* into rendered output (rehypeRaw renders the `\` literally, e.g. `<div>{foo</div>`).
|
|
124200
|
+
*
|
|
124201
|
+
* One carve-out: if an interior line at column 0 has bare text containing `{`, mdxish
|
|
124202
|
+
* parses that line as a paragraph and the mdxExpression step would throw without an
|
|
124203
|
+
* escape — so we leave that case to the brace balancer.
|
|
124204
|
+
*/
|
|
124205
|
+
function protectHTMLElements(content) {
|
|
124206
|
+
const htmlElements = [];
|
|
124207
|
+
const protectedContent = content.replace(BLOCK_HTML_RE, match => {
|
|
124208
|
+
// Look at the lines between the open and close tags. If any of them starts
|
|
124209
|
+
// at column 0 with bare text (not whitespace, not another tag) and contains
|
|
124210
|
+
// `{`, mdxish will parse that line as a paragraph and the brace as an MDX
|
|
124211
|
+
// expression, which would throw an error. So we let the brace balancer escape it.
|
|
124212
|
+
// Otherwise, we need to extract the sequence to protect it from the brace escaping.
|
|
124213
|
+
const interior = match.split('\n').slice(1, -1);
|
|
124214
|
+
const hazard = interior.some(line => line.length > 0 && line[0] !== ' ' && line[0] !== '\t' && line[0] !== '<' && line.includes('{'));
|
|
124215
|
+
if (hazard)
|
|
124216
|
+
return match;
|
|
124217
|
+
htmlElements.push(match);
|
|
124218
|
+
return `${HTML_ELEM_PLACEHOLDER_PREFIX}${htmlElements.length - 1}___`;
|
|
124219
|
+
});
|
|
124220
|
+
return { htmlElements, protectedContent };
|
|
124221
|
+
}
|
|
124222
|
+
function restoreHTMLElements(content, htmlElements) {
|
|
124223
|
+
if (htmlElements.length === 0)
|
|
124224
|
+
return content;
|
|
124225
|
+
return content.replace(HTML_ELEM_PLACEHOLDER, (_m, idx) => htmlElements[parseInt(idx, 10)]);
|
|
124226
|
+
}
|
|
124227
|
+
/**
|
|
124228
|
+
* Escapes unbalanced and paragraph-spanning braces so MDX doesn't trip on them.
|
|
124229
|
+
*/
|
|
124230
|
+
function escapeProblematicBraces(content) {
|
|
124231
|
+
const { htmlElements, protectedContent } = protectHTMLElements(content);
|
|
124232
|
+
let strDelim = null;
|
|
124233
|
+
let strEscaped = false;
|
|
124234
|
+
// Track position of last newline (outside strings) to detect blank lines
|
|
124235
|
+
// -2 means no recent newline
|
|
124236
|
+
let lastNewlinePos = -2;
|
|
124237
|
+
// Character state machine trackers
|
|
124238
|
+
const toEscape = new Set();
|
|
124239
|
+
// Convert to array of Unicode code points so that emojis and multi-byte characters are correctly tracked
|
|
124240
|
+
const chars = Array.from(protectedContent);
|
|
124241
|
+
const openStack = [];
|
|
124242
|
+
for (let i = 0; i < chars.length; i += 1) {
|
|
124243
|
+
const ch = chars[i];
|
|
124244
|
+
// Track string delimiters inside expressions to ignore braces within them
|
|
124245
|
+
if (openStack.length > 0) {
|
|
124246
|
+
if (strDelim) {
|
|
124247
|
+
if (strEscaped)
|
|
124248
|
+
strEscaped = false;
|
|
124249
|
+
else if (ch === '\\')
|
|
124250
|
+
strEscaped = true;
|
|
124251
|
+
else if (ch === strDelim)
|
|
124252
|
+
strDelim = null;
|
|
124253
|
+
// eslint-disable-next-line no-continue
|
|
124254
|
+
continue;
|
|
124255
|
+
}
|
|
124256
|
+
if (ch === '"' || ch === "'" || ch === '`') {
|
|
124257
|
+
strDelim = ch;
|
|
124258
|
+
// eslint-disable-next-line no-continue
|
|
124259
|
+
continue;
|
|
124260
|
+
}
|
|
124261
|
+
if (ch === '\n') {
|
|
124262
|
+
if (lastNewlinePos >= 0) {
|
|
124263
|
+
const between = chars.slice(lastNewlinePos + 1, i).join('');
|
|
124264
|
+
if (/^[ \t]*$/.test(between)) {
|
|
124265
|
+
openStack.forEach(entry => { entry.hasBlankLine = true; });
|
|
124266
|
+
}
|
|
124267
|
+
}
|
|
124268
|
+
lastNewlinePos = i;
|
|
124269
|
+
}
|
|
124270
|
+
}
|
|
124271
|
+
// Skip already-escaped braces (odd run of preceding backslashes).
|
|
124272
|
+
if (ch === '{' || ch === '}') {
|
|
124273
|
+
let bs = 0;
|
|
124274
|
+
for (let j = i - 1; j >= 0 && chars[j] === '\\'; j -= 1)
|
|
124275
|
+
bs += 1;
|
|
124276
|
+
if (bs % 2 === 1) {
|
|
124277
|
+
// eslint-disable-next-line no-continue
|
|
124278
|
+
continue;
|
|
124279
|
+
}
|
|
124280
|
+
}
|
|
124281
|
+
if (ch === '{') {
|
|
124282
|
+
// `=` (after whitespace) before `{` ⇒ JSX attribute expression. The
|
|
124283
|
+
// mdxComponent tokenizer captures the whole component, so blank lines
|
|
124284
|
+
// inside attribute values are harmless. Nested `{` inherits the flag.
|
|
124285
|
+
let isAttrExpr = false;
|
|
124286
|
+
for (let j = i - 1; j >= 0; j -= 1) {
|
|
124287
|
+
const pc = chars[j];
|
|
124288
|
+
if (pc === '=') {
|
|
124289
|
+
isAttrExpr = true;
|
|
124290
|
+
break;
|
|
124291
|
+
}
|
|
124292
|
+
if (pc !== ' ' && pc !== '\t')
|
|
124293
|
+
break;
|
|
124294
|
+
}
|
|
124295
|
+
// Nested `{ ... }` inside an attribute value (e.g. `data={[{ ... }]}` or
|
|
124296
|
+
// `data={{ a: { b: 1 } }}`) must inherit the same exemption; only the
|
|
124297
|
+
// outer `{` is directly after `=`.
|
|
124298
|
+
if (!isAttrExpr && openStack.length > 0 && openStack[openStack.length - 1].isAttrExpr) {
|
|
124299
|
+
isAttrExpr = true;
|
|
124300
|
+
}
|
|
124301
|
+
openStack.push({ pos: i, hasBlankLine: false, isAttrExpr });
|
|
124302
|
+
lastNewlinePos = -2;
|
|
124303
|
+
}
|
|
124304
|
+
else if (ch === '}') {
|
|
124305
|
+
if (openStack.length > 0) {
|
|
124306
|
+
const entry = openStack.pop();
|
|
124307
|
+
// Pure `{/* ... */}` comments are handled downstream by the jsxComment
|
|
124308
|
+
// tokenizer — escaping their braces would prevent it from running.
|
|
124309
|
+
const isPureJsxComment = chars[entry.pos + 1] === '/' &&
|
|
124310
|
+
chars[entry.pos + 2] === '*' &&
|
|
124311
|
+
chars[i - 1] === '/' &&
|
|
124312
|
+
chars[i - 2] === '*';
|
|
124313
|
+
if (entry.hasBlankLine && !isPureJsxComment && !entry.isAttrExpr) {
|
|
124314
|
+
toEscape.add(entry.pos);
|
|
124315
|
+
toEscape.add(i);
|
|
124316
|
+
}
|
|
124317
|
+
}
|
|
124318
|
+
else {
|
|
124319
|
+
toEscape.add(i);
|
|
124320
|
+
}
|
|
124321
|
+
}
|
|
124322
|
+
}
|
|
124323
|
+
// Anything still open is unbalanced.
|
|
124324
|
+
openStack.forEach(entry => toEscape.add(entry.pos));
|
|
124325
|
+
// Reconstruct the content with the escaped braces.
|
|
124326
|
+
const escapedContent = toEscape.size === 0 ? protectedContent : chars.map((ch, i) => (toEscape.has(i) ? `\\${ch}` : ch)).join('');
|
|
124327
|
+
return restoreHTMLElements(escapedContent, htmlElements);
|
|
124328
|
+
}
|
|
124329
|
+
/**
|
|
124330
|
+
* Preprocesses JSX-like markdown content before parsing.
|
|
124331
|
+
*
|
|
124332
|
+
* JSX attribute expressions (`href={baseUrl}`) are no longer rewritten here —
|
|
124333
|
+
* they flow through the tokenizer as `mdxJsxAttributeValueExpression` nodes
|
|
124334
|
+
* and are evaluated at the hast handler step.
|
|
124335
|
+
*
|
|
124336
|
+
* @param content
|
|
124337
|
+
* @returns Preprocessed content ready for markdown parsing
|
|
124338
|
+
*/
|
|
124339
|
+
function preprocessJSXExpressions(content) {
|
|
124340
|
+
const { protectedCode, protectedContent } = protectCodeBlocks(content);
|
|
124341
|
+
let processed = escapeProblematicBraces(protectedContent);
|
|
124342
|
+
processed = restoreCodeBlocks(processed, protectedCode);
|
|
124343
|
+
return processed;
|
|
124344
|
+
}
|
|
124345
|
+
|
|
124520
124346
|
;// ./processor/transform/mdxish/restore-snake-case-component-name.ts
|
|
124521
124347
|
|
|
124522
124348
|
|
|
@@ -125633,7 +125459,7 @@ function mdxishAstProcessor(mdContent, opts = {}) {
|
|
|
125633
125459
|
.use(inline_html, { safeMode })
|
|
125634
125460
|
.use(restore_snake_case_component_name, { mapping: snakeCaseMapping })
|
|
125635
125461
|
.use(mdxish_tables)
|
|
125636
|
-
.use(mdxish_html_blocks)
|
|
125462
|
+
.use(mdxish_html_blocks) // Convert every <HTMLBlock> shape → html-block
|
|
125637
125463
|
// The next few transformers must appear after mdxishMdxComponentBlocks
|
|
125638
125464
|
// so nodes produced by the inline re-parse of component bodies
|
|
125639
125465
|
// (e.g. code/image/embed inside <Tabs>) get visited too
|