@readme/markdown 15.9.0 → 15.9.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/Callout/style.scss +8 -0
- package/components/HTMLBlock/index.tsx +2 -2
- package/dist/main.css +1 -1
- package/dist/main.css.map +1 -1
- package/dist/main.js +204 -162
- package/dist/main.node.js +204 -162
- package/dist/main.node.js.map +1 -1
- package/dist/processor/transform/mdxish/components/utils.d.ts +0 -7
- package/dist/processor/transform/mdxish/magic-blocks/types.d.ts +1 -0
- package/dist/processor/transform/mdxish/reparse-source.d.ts +18 -0
- package/dist/processor/transform/mdxish/tables/mdxish-tables.d.ts +3 -2
- package/dist/processor/transform/mdxish/tables/split-nested-tables.d.ts +3 -2
- package/dist/processor/utils.d.ts +4 -5
- package/dist/render-fixture.node.js +204 -163
- package/dist/render-fixture.node.js.map +1 -1
- package/package.json +1 -1
- package/types.d.ts +2 -2
- package/dist/processor/plugin/safe-mode-html-blocks.d.ts +0 -12
|
@@ -19045,7 +19045,7 @@ module.exports = function () {
|
|
|
19045
19045
|
|
|
19046
19046
|
/***/ },
|
|
19047
19047
|
|
|
19048
|
-
/***/
|
|
19048
|
+
/***/ 1186
|
|
19049
19049
|
(module, __webpack_exports__, __webpack_require__) {
|
|
19050
19050
|
|
|
19051
19051
|
"use strict";
|
|
@@ -68781,18 +68781,53 @@ function evaluate(source, scope = {}) {
|
|
|
68781
68781
|
return new Function(...names, `return (${source})`)(...values);
|
|
68782
68782
|
}
|
|
68783
68783
|
/**
|
|
68784
|
-
*
|
|
68785
|
-
*
|
|
68786
|
-
*
|
|
68784
|
+
* Width each container prefix adds back per line of `value`, aligned from the line end since a
|
|
68785
|
+
* tab in the prefix is expanded to spaces in `value`. None (a verbatim slice) when the source
|
|
68786
|
+
* is missing or doesn't line up.
|
|
68787
68787
|
*/
|
|
68788
|
-
const
|
|
68789
|
-
const
|
|
68790
|
-
const
|
|
68791
|
-
|
|
68792
|
-
|
|
68793
|
-
|
|
68794
|
-
|
|
68795
|
-
|
|
68788
|
+
const containerPrefixWidths = (valueLines, source, position) => {
|
|
68789
|
+
const sourceLines = source?.slice(position.start.offset, position.end.offset).split('\n');
|
|
68790
|
+
const linesUp = sourceLines?.length === valueLines.length &&
|
|
68791
|
+
sourceLines.every((line, i) => line.endsWith(valueLines[i].trimStart()));
|
|
68792
|
+
return valueLines.map((line, i) => (linesUp ? sourceLines[i].length - line.length : 0));
|
|
68793
|
+
};
|
|
68794
|
+
/**
|
|
68795
|
+
* Maps offsets in a node's `value` to points in `source`. Containers strip a prefix from every
|
|
68796
|
+
* continuation line of `value`, so a plain offset shift drifts by line (CX-4028).
|
|
68797
|
+
*/
|
|
68798
|
+
const createValueToSourceMapper = (position, value, source) => {
|
|
68799
|
+
if (position?.start.offset === undefined)
|
|
68800
|
+
return null;
|
|
68801
|
+
const { start } = position;
|
|
68802
|
+
const valueLines = value.split('\n');
|
|
68803
|
+
const prefixWidths = containerPrefixWidths(valueLines, source, position);
|
|
68804
|
+
const lines = [];
|
|
68805
|
+
let valueStart = 0;
|
|
68806
|
+
let sourceStart = start.offset;
|
|
68807
|
+
valueLines.forEach((line, i) => {
|
|
68808
|
+
lines.push({ prefixWidth: prefixWidths[i], sourceStart, valueStart });
|
|
68809
|
+
valueStart += line.length + 1;
|
|
68810
|
+
sourceStart += prefixWidths[i] + line.length + 1;
|
|
68811
|
+
});
|
|
68812
|
+
return valueOffset => {
|
|
68813
|
+
// Binary search: a large table maps one point per node.
|
|
68814
|
+
let low = 0;
|
|
68815
|
+
let high = lines.length - 1;
|
|
68816
|
+
while (low < high) {
|
|
68817
|
+
const mid = Math.ceil((low + high) / 2);
|
|
68818
|
+
if (lines[mid].valueStart <= valueOffset)
|
|
68819
|
+
low = mid;
|
|
68820
|
+
else
|
|
68821
|
+
high = mid - 1;
|
|
68822
|
+
}
|
|
68823
|
+
const { prefixWidth, sourceStart: lineSourceStart, valueStart: lineValueStart } = lines[low];
|
|
68824
|
+
// Clamped: an expanded tab can make a leading-whitespace offset fall before the line.
|
|
68825
|
+
const sourceColumn = Math.max(0, prefixWidth + valueOffset - lineValueStart);
|
|
68826
|
+
return {
|
|
68827
|
+
line: start.line + low,
|
|
68828
|
+
column: (low === 0 ? start.column : 1) + sourceColumn,
|
|
68829
|
+
offset: lineSourceStart + sourceColumn,
|
|
68830
|
+
};
|
|
68796
68831
|
};
|
|
68797
68832
|
};
|
|
68798
68833
|
/**
|
|
@@ -69455,7 +69490,9 @@ const processBlockquote = (node, index, parent, isMdxish = false) => {
|
|
|
69455
69490
|
}
|
|
69456
69491
|
Object.assign(node, {
|
|
69457
69492
|
type: NodeTypes.callout,
|
|
69493
|
+
// Keep the blockquote's data, e.g. the `reparseSource` its positions index into.
|
|
69458
69494
|
data: {
|
|
69495
|
+
...node.data,
|
|
69459
69496
|
hName: 'Callout',
|
|
69460
69497
|
hProperties: {
|
|
69461
69498
|
icon,
|
|
@@ -69488,14 +69525,55 @@ const calloutTransformer = ({ isMdxish = false } = {}) => {
|
|
|
69488
69525
|
};
|
|
69489
69526
|
/* harmony default export */ const callouts = (calloutTransformer);
|
|
69490
69527
|
|
|
69528
|
+
;// ./processor/transform/mdxish/reparse-source.ts
|
|
69529
|
+
/**
|
|
69530
|
+
* Mark re-parsed subtree roots with the string their positions index into, so consumers
|
|
69531
|
+
* slicing by offset use the right source (see `Data.reparseSource`). Only roots are
|
|
69532
|
+
* stamped; descendants resolve via their nearest stamped ancestor. Roots a deeper
|
|
69533
|
+
* re-parse already stamped keep their own string.
|
|
69534
|
+
*/
|
|
69535
|
+
const stampReparseSource = (roots, reparseSource) => {
|
|
69536
|
+
roots.forEach(root => {
|
|
69537
|
+
if (!root.data?.reparseSource)
|
|
69538
|
+
root.data = { ...root.data, reparseSource };
|
|
69539
|
+
});
|
|
69540
|
+
};
|
|
69541
|
+
/**
|
|
69542
|
+
* Splice `replacements` over `parent.children[index]`. They take over the replaced node's
|
|
69543
|
+
* position, so they also take over the coordinate space that position indexes into.
|
|
69544
|
+
*/
|
|
69545
|
+
const replaceInheritingReparseSource = (parent, index, replacements) => {
|
|
69546
|
+
const replacedSource = parent.children[index]?.data?.reparseSource;
|
|
69547
|
+
if (replacedSource)
|
|
69548
|
+
stampReparseSource(replacements, replacedSource);
|
|
69549
|
+
parent.children.splice(index, 1, ...replacements);
|
|
69550
|
+
};
|
|
69551
|
+
/**
|
|
69552
|
+
* The string `node`'s offsets index into: the nearest stamp on it or an ancestor, else the
|
|
69553
|
+
* document source.
|
|
69554
|
+
*/
|
|
69555
|
+
const resolveReparseSource = (node, ancestors, documentSource) => {
|
|
69556
|
+
if (node.data?.reparseSource)
|
|
69557
|
+
return node.data.reparseSource;
|
|
69558
|
+
for (let i = ancestors.length - 1; i >= 0; i -= 1) {
|
|
69559
|
+
const { reparseSource } = ancestors[i].data ?? {};
|
|
69560
|
+
if (reparseSource)
|
|
69561
|
+
return reparseSource;
|
|
69562
|
+
}
|
|
69563
|
+
return documentSource;
|
|
69564
|
+
};
|
|
69565
|
+
|
|
69491
69566
|
;// ./processor/transform/code-tabs.ts
|
|
69492
69567
|
|
|
69493
69568
|
|
|
69569
|
+
|
|
69494
69570
|
const isCode = (node) => node?.type === 'code';
|
|
69495
69571
|
const codeTabsTransformer = ({ copyButtons } = {}) => (tree) => {
|
|
69496
69572
|
visit(tree, 'code', (node) => {
|
|
69497
69573
|
const { lang, meta, value } = node;
|
|
69498
69574
|
node.data = {
|
|
69575
|
+
// Ensure positions are passed through
|
|
69576
|
+
...node.data,
|
|
69499
69577
|
hProperties: { lang, meta, value, copyButtons },
|
|
69500
69578
|
};
|
|
69501
69579
|
});
|
|
@@ -69542,6 +69620,9 @@ const codeTabsTransformer = ({ copyButtons } = {}) => (tree) => {
|
|
|
69542
69620
|
end: children[children.length - 1].position.end,
|
|
69543
69621
|
},
|
|
69544
69622
|
};
|
|
69623
|
+
// Adjacent siblings share a coordinate space, so the wrapper takes the first block's.
|
|
69624
|
+
if (node.data?.reparseSource)
|
|
69625
|
+
stampReparseSource([codeTabs], node.data.reparseSource);
|
|
69545
69626
|
parent.children.splice(index, children.length, codeTabs);
|
|
69546
69627
|
});
|
|
69547
69628
|
return tree;
|
|
@@ -92178,9 +92259,9 @@ const HTMLBlock = ({ children = '', html: htmlProp, runScripts, safeMode: safeMo
|
|
|
92178
92259
|
const safeMode = typeof safeModeRaw !== 'boolean' ? safeModeRaw === 'true' : safeModeRaw;
|
|
92179
92260
|
const [cleanedHtml, exec] = extractScripts(html);
|
|
92180
92261
|
(0,external_react_.useEffect)(() => {
|
|
92181
|
-
if (typeof window !== 'undefined' && typeof runScripts === 'boolean' && runScripts
|
|
92262
|
+
if (typeof window !== 'undefined' && typeof runScripts === 'boolean' && runScripts)
|
|
92182
92263
|
exec();
|
|
92183
|
-
}, [runScripts,
|
|
92264
|
+
}, [runScripts, exec]);
|
|
92184
92265
|
if (nonStringChildren) {
|
|
92185
92266
|
// Fail soft: a non-string child (e.g. JSX that wasn't serialized back to a
|
|
92186
92267
|
// raw string) should never throw, so render the child nodes directly
|
|
@@ -100237,6 +100318,7 @@ const walkTags = (html, handlers) => {
|
|
|
100237
100318
|
};
|
|
100238
100319
|
|
|
100239
100320
|
;// ./processor/transform/mdxish/tables/utils.ts
|
|
100321
|
+
|
|
100240
100322
|
const tableTags = new Set([
|
|
100241
100323
|
'thead',
|
|
100242
100324
|
'tbody',
|
|
@@ -100255,6 +100337,9 @@ const tableTags = new Set([
|
|
|
100255
100337
|
const unwrapParagraphNodes = (children) => {
|
|
100256
100338
|
return children.flatMap(child => {
|
|
100257
100339
|
if (child.type === 'paragraph' && 'children' in child && Array.isArray(child.children)) {
|
|
100340
|
+
// The unwrap drops a stamped root, so its children inherit that coordinate space.
|
|
100341
|
+
if (child.data?.reparseSource)
|
|
100342
|
+
stampReparseSource(child.children, child.data.reparseSource);
|
|
100258
100343
|
return child.children;
|
|
100259
100344
|
}
|
|
100260
100345
|
return [child];
|
|
@@ -100850,9 +100935,10 @@ const findTableRanges = (html) => {
|
|
|
100850
100935
|
* The surrounding raw HTML (the wrapper's open/close tags) would be re-nested
|
|
100851
100936
|
* around the parsed tables by rehype-raw.
|
|
100852
100937
|
*
|
|
100853
|
-
* Returns null when there is no wrapped table to extract.
|
|
100938
|
+
* Returns null when there is no wrapped table to extract. `source` is the string the node's
|
|
100939
|
+
* positions index into, so the parts' positions survive stripped container prefixes.
|
|
100854
100940
|
*/
|
|
100855
|
-
const splitHtmlWithNestedTables = (node) => {
|
|
100941
|
+
const splitHtmlWithNestedTables = (node, source) => {
|
|
100856
100942
|
const { value } = node;
|
|
100857
100943
|
// This is a top-level table, so we don't need to split it
|
|
100858
100944
|
if (TOP_LEVEL_TABLE_TAG_RE.test(value))
|
|
@@ -100865,13 +100951,11 @@ const splitHtmlWithNestedTables = (node) => {
|
|
|
100865
100951
|
const ranges = findTableRanges(value);
|
|
100866
100952
|
if (ranges.length === 0)
|
|
100867
100953
|
return null;
|
|
100868
|
-
const
|
|
100954
|
+
const toSourcePoint = createValueToSourceMapper(node.position, value, source);
|
|
100869
100955
|
const sliceToHtml = (from, to) => ({
|
|
100870
100956
|
type: 'html',
|
|
100871
100957
|
value: value.slice(from, to),
|
|
100872
|
-
...(
|
|
100873
|
-
position: { start: pointAfter(base, value.slice(0, from)), end: pointAfter(base, value.slice(0, to)) },
|
|
100874
|
-
}),
|
|
100958
|
+
...(toSourcePoint && { position: { start: toSourcePoint(from), end: toSourcePoint(to) } }),
|
|
100875
100959
|
});
|
|
100876
100960
|
const parts = [];
|
|
100877
100961
|
let cursor = 0;
|
|
@@ -100906,6 +100990,8 @@ const splitHtmlWithNestedTables = (node) => {
|
|
|
100906
100990
|
|
|
100907
100991
|
|
|
100908
100992
|
|
|
100993
|
+
|
|
100994
|
+
|
|
100909
100995
|
|
|
100910
100996
|
|
|
100911
100997
|
|
|
@@ -100958,7 +101044,7 @@ const tableRepairs = [
|
|
|
100958
101044
|
* The plugins in the processor allows parsing markdown & special syntax inside the table cells
|
|
100959
101045
|
* After parsing, we need to update the node positions
|
|
100960
101046
|
*/
|
|
100961
|
-
const parseTableNode = (processor, node, repair) => {
|
|
101047
|
+
const parseTableNode = (processor, node, source, repair) => {
|
|
100962
101048
|
let parsed;
|
|
100963
101049
|
try {
|
|
100964
101050
|
parsed = processor.runSync(processor.parse(node.value));
|
|
@@ -100972,19 +101058,18 @@ const parseTableNode = (processor, node, repair) => {
|
|
|
100972
101058
|
if (repair) {
|
|
100973
101059
|
remapPositionsThroughLayers(parsed, repair.originalSource, repair.layers);
|
|
100974
101060
|
}
|
|
100975
|
-
// The subparser produces positions relative to `node.value`;
|
|
100976
|
-
// the outer
|
|
100977
|
-
const
|
|
100978
|
-
|
|
101061
|
+
// The subparser produces positions relative to `node.value`; map them into
|
|
101062
|
+
// the outer source so consumers can slice it.
|
|
101063
|
+
const toSourcePoint = createValueToSourceMapper(node.position, repair?.originalSource ?? node.value, source);
|
|
101064
|
+
if (!toSourcePoint)
|
|
101065
|
+
return parsed;
|
|
100979
101066
|
visit(parsed, child => {
|
|
100980
|
-
if (child.position
|
|
100981
|
-
|
|
100982
|
-
|
|
100983
|
-
|
|
100984
|
-
|
|
100985
|
-
|
|
100986
|
-
child.position.end.line += baseLine;
|
|
100987
|
-
}
|
|
101067
|
+
if (!child.position)
|
|
101068
|
+
return;
|
|
101069
|
+
child.position = {
|
|
101070
|
+
start: toSourcePoint(child.position.start.offset ?? 0),
|
|
101071
|
+
end: toSourcePoint(child.position.end.offset ?? 0),
|
|
101072
|
+
};
|
|
100988
101073
|
});
|
|
100989
101074
|
return parsed;
|
|
100990
101075
|
};
|
|
@@ -101014,12 +101099,10 @@ const hasFlowContent = (nodes) => {
|
|
|
101014
101099
|
return nodes.some(node => !phrasing(node) && node.type !== 'paragraph');
|
|
101015
101100
|
};
|
|
101016
101101
|
/**
|
|
101017
|
-
* Process a Table node: re-parse text-only cell content, then
|
|
101018
|
-
* a markdown table (phrasing-only) or keep as JSX <Table> (has flow content).
|
|
101102
|
+
* Process a Table node: re-parse text-only cell content, then return it as
|
|
101103
|
+
* a markdown table (phrasing-only) or keep it as JSX <Table> (has flow content).
|
|
101019
101104
|
*/
|
|
101020
|
-
const processTableNode = (node,
|
|
101021
|
-
if (node.name !== 'Table' && node.name !== 'table')
|
|
101022
|
-
return;
|
|
101105
|
+
const processTableNode = (node, documentPosition) => {
|
|
101023
101106
|
const position = documentPosition ?? node.position;
|
|
101024
101107
|
const { align: alignAttr } = getAttrs(node);
|
|
101025
101108
|
const align = Array.isArray(alignAttr) ? alignAttr : null;
|
|
@@ -101046,6 +101129,8 @@ const processTableNode = (node, index, parent, documentPosition) => {
|
|
|
101046
101129
|
try {
|
|
101047
101130
|
const parsed = tableNodeProcessor.runSync(tableNodeProcessor.parse(textContent));
|
|
101048
101131
|
if (parsed.children.length > 0) {
|
|
101132
|
+
// Positions index into the extracted text rather than the table source (CX-4004).
|
|
101133
|
+
stampReparseSource(parsed.children, textContent);
|
|
101049
101134
|
cell.children = parsed.children;
|
|
101050
101135
|
if (hasFlowContent(parsed.children)) {
|
|
101051
101136
|
tableHasFlowContent = true;
|
|
@@ -101088,11 +101173,7 @@ const processTableNode = (node, index, parent, documentPosition) => {
|
|
|
101088
101173
|
: unwrapParagraphNodes(el.children);
|
|
101089
101174
|
el.children = removeWhitespaceOnlyTextNodes(unwrapped);
|
|
101090
101175
|
});
|
|
101091
|
-
|
|
101092
|
-
...node,
|
|
101093
|
-
position,
|
|
101094
|
-
};
|
|
101095
|
-
return;
|
|
101176
|
+
return { ...node, position };
|
|
101096
101177
|
}
|
|
101097
101178
|
// All cells are phrasing-only — convert to markdown table
|
|
101098
101179
|
const children = [];
|
|
@@ -101170,7 +101251,7 @@ const processTableNode = (node, index, parent, documentPosition) => {
|
|
|
101170
101251
|
const alignArray = align && columnCount > 0
|
|
101171
101252
|
? align.slice(0, columnCount).concat(new Array(Math.max(0, columnCount - align.length)).fill(null))
|
|
101172
101253
|
: new Array(columnCount).fill(null);
|
|
101173
|
-
|
|
101254
|
+
return {
|
|
101174
101255
|
align: alignArray,
|
|
101175
101256
|
type: 'table',
|
|
101176
101257
|
position,
|
|
@@ -101178,14 +101259,13 @@ const processTableNode = (node, index, parent, documentPosition) => {
|
|
|
101178
101259
|
// Remember the author's spelling so the serializer can write `<table>` back instead of `<Table>`
|
|
101179
101260
|
...(node.name === 'table' && { data: { lowercaseTable: true } }),
|
|
101180
101261
|
};
|
|
101181
|
-
parent.children[index] = mdNode;
|
|
101182
101262
|
};
|
|
101183
101263
|
/**
|
|
101184
101264
|
* Apply `tableRepairs` cumulatively, re-parsing after every change and stopping
|
|
101185
101265
|
* once the accumulated result parses. Each layer's inserts are relative to the
|
|
101186
101266
|
* string that repair received, so they stay ordered for position remapping.
|
|
101187
101267
|
*/
|
|
101188
|
-
const repairAndReparse = (node) => {
|
|
101268
|
+
const repairAndReparse = (node, source) => {
|
|
101189
101269
|
let repairedValue = node.value;
|
|
101190
101270
|
const layers = [];
|
|
101191
101271
|
let parsed;
|
|
@@ -101195,11 +101275,45 @@ const repairAndReparse = (node) => {
|
|
|
101195
101275
|
return false;
|
|
101196
101276
|
repairedValue = value;
|
|
101197
101277
|
layers.push(inserts);
|
|
101198
|
-
parsed = parseTableNode(tableNodeProcessor, { ...node, value: repairedValue },
|
|
101278
|
+
parsed = parseTableNode(tableNodeProcessor, { ...node, value: repairedValue }, source, {
|
|
101279
|
+
layers,
|
|
101280
|
+
originalSource: node.value,
|
|
101281
|
+
});
|
|
101199
101282
|
return Boolean(parsed);
|
|
101200
101283
|
});
|
|
101201
101284
|
return parsed;
|
|
101202
101285
|
};
|
|
101286
|
+
/**
|
|
101287
|
+
* Re-parse a table html node and replace it with a markdown / JSX table, or the
|
|
101288
|
+
* fallback parse's fragments for a lowercase table mdxjs rejects.
|
|
101289
|
+
*/
|
|
101290
|
+
const replaceTableHtml = (node, index, parent, source) => {
|
|
101291
|
+
// Because the processor uses remarkMdx, it is stricter in what it accepts
|
|
101292
|
+
// and only accepts valid MDX syntax in the table node. To get around that,
|
|
101293
|
+
// fall back to the cumulative repairs when the first parse fails.
|
|
101294
|
+
const parsed = parseTableNode(tableNodeProcessor, node, source) ?? repairAndReparse(node, source);
|
|
101295
|
+
if (parsed) {
|
|
101296
|
+
// If the table is parsed successfully, we can now process it further
|
|
101297
|
+
// to build on the markdown / JSX table
|
|
101298
|
+
visit(parsed, isMDXElement, (tableNode) => {
|
|
101299
|
+
if (tableNode.name !== 'Table' && tableNode.name !== 'table')
|
|
101300
|
+
return undefined;
|
|
101301
|
+
replaceInheritingReparseSource(parent, index, [processTableNode(tableNode, node.position)]);
|
|
101302
|
+
return (/* inlined export .EXIT */false);
|
|
101303
|
+
});
|
|
101304
|
+
}
|
|
101305
|
+
else if (node.value.startsWith('<table')) {
|
|
101306
|
+
// If the parsing still fails, give an opportunity to the fallback parser
|
|
101307
|
+
// without remarkMdx to process lowercase tables as it's likely to not
|
|
101308
|
+
// have needed MDX parsing anyway
|
|
101309
|
+
const fallback = parseTableNode(fallbackTableNodeProcessor, node, source);
|
|
101310
|
+
if (!fallback || fallback.children.length <= 1)
|
|
101311
|
+
return;
|
|
101312
|
+
replaceInheritingReparseSource(parent, index, fallback.children);
|
|
101313
|
+
}
|
|
101314
|
+
// Otherwise, there's no point in trying to parse the table content further
|
|
101315
|
+
// More repairs are needed in that case
|
|
101316
|
+
};
|
|
101203
101317
|
/**
|
|
101204
101318
|
* Converts JSX Table elements to markdown table nodes and re-parses markdown in cells.
|
|
101205
101319
|
*
|
|
@@ -101211,24 +101325,26 @@ const repairAndReparse = (node) => {
|
|
|
101211
101325
|
* When cell content contains block-level nodes (callouts, code blocks, etc.), the table
|
|
101212
101326
|
* is kept as a JSX <Table> element so that remarkRehype can properly handle the flow content.
|
|
101213
101327
|
*/
|
|
101214
|
-
const mdxishTables = () => tree => {
|
|
101328
|
+
const mdxishTables = () => (tree, file) => {
|
|
101329
|
+
// Positions index into the document unless a re-parse stamped another source.
|
|
101330
|
+
const documentSource = file?.value ? String(file.value) : undefined;
|
|
101215
101331
|
// Pre-pass: lift `<table>`s wrapped in a raw HTML block out into their own
|
|
101216
101332
|
// html nodes so the main pass below treats them like top-level tables.
|
|
101217
|
-
|
|
101218
|
-
const
|
|
101219
|
-
if (
|
|
101333
|
+
visitParents(tree, 'html', (node, ancestors) => {
|
|
101334
|
+
const parent = ancestors[ancestors.length - 1];
|
|
101335
|
+
if (!parent)
|
|
101220
101336
|
return;
|
|
101221
|
-
const parts = splitHtmlWithNestedTables(node);
|
|
101337
|
+
const parts = splitHtmlWithNestedTables(node, resolveReparseSource(node, ancestors, documentSource));
|
|
101222
101338
|
if (!parts)
|
|
101223
101339
|
return;
|
|
101224
101340
|
// The inserted parts can't re-trigger a split (table parts start with
|
|
101225
101341
|
// `<table`; the wrapper slices hold no table), so plain in-place splicing
|
|
101226
101342
|
// visits each once without looping.
|
|
101227
|
-
parent.children.
|
|
101343
|
+
replaceInheritingReparseSource(parent, parent.children.indexOf(node), parts);
|
|
101228
101344
|
});
|
|
101229
|
-
|
|
101230
|
-
const
|
|
101231
|
-
if (
|
|
101345
|
+
visitParents(tree, 'html', (node, ancestors) => {
|
|
101346
|
+
const parent = ancestors[ancestors.length - 1];
|
|
101347
|
+
if (!parent)
|
|
101232
101348
|
return;
|
|
101233
101349
|
if (!node.value.startsWith('<Table') && !node.value.startsWith('<table'))
|
|
101234
101350
|
return;
|
|
@@ -101236,33 +101352,8 @@ const mdxishTables = () => tree => {
|
|
|
101236
101352
|
// paragraph. Leave them untouched so rehype-raw can reassemble the table.
|
|
101237
101353
|
if (parent.type === 'paragraph')
|
|
101238
101354
|
return;
|
|
101239
|
-
|
|
101240
|
-
// and only accepts valid MDX syntax in the table node. To get around that,
|
|
101241
|
-
// fall back to the cumulative repairs when the first parse fails.
|
|
101242
|
-
const parsed = parseTableNode(tableNodeProcessor, node) ?? repairAndReparse(node);
|
|
101243
|
-
if (parsed) {
|
|
101244
|
-
// If the table is parsed successfully, we can now process it further
|
|
101245
|
-
// to build on the markdown / JSX table
|
|
101246
|
-
visit(parsed, isMDXElement, (tableNode) => {
|
|
101247
|
-
if (tableNode.name !== 'Table' && tableNode.name !== 'table')
|
|
101248
|
-
return undefined;
|
|
101249
|
-
processTableNode(tableNode, index, parent, node.position);
|
|
101250
|
-
return (/* inlined export .EXIT */false);
|
|
101251
|
-
});
|
|
101252
|
-
}
|
|
101253
|
-
else if (node.value.startsWith('<table')) {
|
|
101254
|
-
// If the parsing still fails, give an opportunity to the fallback parser
|
|
101255
|
-
// without remarkMdx to process lowercase tables as it's likely to not
|
|
101256
|
-
// have needed MDX parsing anyway
|
|
101257
|
-
const fallback = parseTableNode(fallbackTableNodeProcessor, node);
|
|
101258
|
-
if (!fallback || fallback.children.length <= 1)
|
|
101259
|
-
return;
|
|
101260
|
-
parent.children.splice(index, 1, ...fallback.children);
|
|
101261
|
-
}
|
|
101262
|
-
// Otherwise, there's no point in trying to parse the table content further
|
|
101263
|
-
// More repairs are needed in that case
|
|
101355
|
+
replaceTableHtml(node, parent.children.indexOf(node), parent, resolveReparseSource(node, ancestors, documentSource));
|
|
101264
101356
|
});
|
|
101265
|
-
return tree;
|
|
101266
101357
|
};
|
|
101267
101358
|
/* harmony default export */ const mdxish_tables = (mdxishTables);
|
|
101268
101359
|
|
|
@@ -122425,32 +122516,6 @@ const mdxComponentHandlers = {
|
|
|
122425
122516
|
[NodeTypes.htmlBlock]: htmlBlockHandler,
|
|
122426
122517
|
};
|
|
122427
122518
|
|
|
122428
|
-
;// ./processor/plugin/safe-mode-html-blocks.ts
|
|
122429
|
-
|
|
122430
|
-
|
|
122431
|
-
/**
|
|
122432
|
-
* Whether a tag name renders through the `HTMLBlock` component. Mirrors the
|
|
122433
|
-
* separator-agnostic, case-insensitive lookup in `getComponentName` and the
|
|
122434
|
-
* rehype-react component map, so `html-block`, `HTMLBlock`, `HtmlBlock` and
|
|
122435
|
-
* `htmlblock` all match.
|
|
122436
|
-
*/
|
|
122437
|
-
const isHtmlBlockTag = (tagName) => toPascalCase(tagName).toLowerCase() === 'htmlblock';
|
|
122438
|
-
/**
|
|
122439
|
-
* Forces `safeMode` on every element that renders through `HTMLBlock` so it is
|
|
122440
|
-
* shown as escaped text instead of injected.
|
|
122441
|
-
*
|
|
122442
|
-
* Runs last, so it sees every producer of the element — `[block:html]`,
|
|
122443
|
-
* `<HTMLBlock>` with a template body or an `html` attribute, and a literal
|
|
122444
|
-
* `<html-block>` — and it is unconditional so an author-supplied
|
|
122445
|
-
* `safeMode="false"` can't opt out.
|
|
122446
|
-
*/
|
|
122447
|
-
const enforceSafeModeHtmlBlocks = () => tree => {
|
|
122448
|
-
visit(tree, 'element', node => {
|
|
122449
|
-
if (isHtmlBlockTag(node.tagName))
|
|
122450
|
-
node.properties.safeMode = 'true';
|
|
122451
|
-
});
|
|
122452
|
-
};
|
|
122453
|
-
|
|
122454
122519
|
;// ./processor/transform/mdxish/anchor-to-jsx.ts
|
|
122455
122520
|
/* unused harmony import specifier */ var anchor_to_jsx_visit;
|
|
122456
122521
|
/* unused harmony import specifier */ var anchor_to_jsx_NodeTypes;
|
|
@@ -122490,7 +122555,6 @@ const mdxishAnchorToJsx = () => tree => {
|
|
|
122490
122555
|
|
|
122491
122556
|
;// ./processor/transform/mdxish/callout-to-jsx.ts
|
|
122492
122557
|
/* unused harmony import specifier */ var callout_to_jsx_visit;
|
|
122493
|
-
/* unused harmony import specifier */ var callout_to_jsx_defaultIcons;
|
|
122494
122558
|
/* unused harmony import specifier */ var callout_to_jsx_themes;
|
|
122495
122559
|
/* unused harmony import specifier */ var callout_to_jsx_NodeTypes;
|
|
122496
122560
|
/* unused harmony import specifier */ var callout_to_jsx_toAttributes;
|
|
@@ -122513,9 +122577,9 @@ const mdxishCalloutToJsx = () => tree => {
|
|
|
122513
122577
|
callout_to_jsx_visit(tree, callout_to_jsx_NodeTypes.callout, (node, index, parent) => {
|
|
122514
122578
|
if (!parent || index === undefined)
|
|
122515
122579
|
return;
|
|
122516
|
-
|
|
122517
|
-
|
|
122518
|
-
|
|
122580
|
+
// No default-icon fill: an empty `icon` means the author removed it
|
|
122581
|
+
const { icon } = node.data.hProperties;
|
|
122582
|
+
let { theme } = node.data.hProperties;
|
|
122519
122583
|
if (!theme && icon)
|
|
122520
122584
|
theme = callout_to_jsx_themes[icon] || 'default';
|
|
122521
122585
|
// Mutate in place to keep the children array identity so nested callouts in
|
|
@@ -123066,18 +123130,6 @@ const getInlineMdProcessor = ({ safeMode = false } = {}) => {
|
|
|
123066
123130
|
}
|
|
123067
123131
|
return processor;
|
|
123068
123132
|
};
|
|
123069
|
-
/**
|
|
123070
|
-
* Mark re-parsed subtree roots with the string their positions index into, so consumers
|
|
123071
|
-
* slicing by offset use the right source (see `Data.reparseSource`). Only roots are
|
|
123072
|
-
* stamped; descendants resolve via their nearest stamped ancestor. Roots a deeper
|
|
123073
|
-
* re-parse already stamped keep their own string.
|
|
123074
|
-
*/
|
|
123075
|
-
const stampReparseSource = (roots, reparseSource) => {
|
|
123076
|
-
roots.forEach(root => {
|
|
123077
|
-
if (!root.data?.reparseSource)
|
|
123078
|
-
root.data = { ...root.data, reparseSource };
|
|
123079
|
-
});
|
|
123080
|
-
};
|
|
123081
123133
|
/**
|
|
123082
123134
|
* True when a tag name starts with an uppercase letter — ReadMe's marker for
|
|
123083
123135
|
* a custom MDX component (vs a lowercase HTML tag).
|
|
@@ -123164,6 +123216,7 @@ function findBalancedClosingTagIndex(content, tag) {
|
|
|
123164
123216
|
|
|
123165
123217
|
|
|
123166
123218
|
|
|
123219
|
+
|
|
123167
123220
|
/**
|
|
123168
123221
|
* Parse the body of an inline component as phrasing content. Remark always
|
|
123169
123222
|
* wraps bare text in a paragraph; flatten that single-paragraph wrapper so
|
|
@@ -123415,6 +123468,7 @@ function terminateHtmlFlowBlocks(content) {
|
|
|
123415
123468
|
|
|
123416
123469
|
|
|
123417
123470
|
|
|
123471
|
+
|
|
123418
123472
|
// Matches a JSX attribute expression (e.g. `key={i}`) anywhere in a string. One name
|
|
123419
123473
|
// char suffices for existence — `[\w-]+` backtracked quadratically over huge attributes.
|
|
123420
123474
|
const NESTED_ATTR_EXPRESSION_RE = /[\w-]\s*=\s*\{/;
|
|
@@ -123496,26 +123550,12 @@ const parseSibling = (parent, index, sibling, safeMode, promoted) => {
|
|
|
123496
123550
|
}
|
|
123497
123551
|
};
|
|
123498
123552
|
// Ends the position at `consumedLength` so the component doesn't claim trailing
|
|
123499
|
-
// content the tokenizer swallowed into the same html node.
|
|
123500
|
-
// when available: each value line is its source line minus the container prefix
|
|
123501
|
-
// (list indent, `> `) micromark stripped, so those prefixes are counted back in.
|
|
123553
|
+
// content the tokenizer swallowed into the same html node.
|
|
123502
123554
|
const positionEndingAtConsumed = (nodePosition, value, consumedLength, source) => {
|
|
123503
|
-
|
|
123555
|
+
const toSourcePoint = createValueToSourceMapper(nodePosition, value, source);
|
|
123556
|
+
if (!nodePosition || !toSourcePoint)
|
|
123504
123557
|
return nodePosition;
|
|
123505
|
-
|
|
123506
|
-
const sourceLines = source?.slice(nodePosition.start.offset, nodePosition.end?.offset).split('\n');
|
|
123507
|
-
const valueLines = value.split('\n');
|
|
123508
|
-
if (!sourceLines || sourceLines.length !== valueLines.length) {
|
|
123509
|
-
return { start: nodePosition.start, end: pointAfter(nodePosition.start, consumedValue) };
|
|
123510
|
-
}
|
|
123511
|
-
const consumedLines = consumedValue.split('\n');
|
|
123512
|
-
const lastLineIndex = consumedLines.length - 1;
|
|
123513
|
-
const prefixWidth = sourceLines[lastLineIndex].length - valueLines[lastLineIndex].length;
|
|
123514
|
-
const consumedSource = [
|
|
123515
|
-
...sourceLines.slice(0, lastLineIndex),
|
|
123516
|
-
sourceLines[lastLineIndex].slice(0, prefixWidth + consumedLines[lastLineIndex].length),
|
|
123517
|
-
].join('\n');
|
|
123518
|
-
return { start: nodePosition.start, end: pointAfter(nodePosition.start, consumedSource) };
|
|
123558
|
+
return { start: nodePosition.start, end: toSourcePoint(consumedLength) };
|
|
123519
123559
|
};
|
|
123520
123560
|
const createComponentNode = ({ tag, attributes, children, startPosition, endPosition, }) => ({
|
|
123521
123561
|
type: 'mdxJsxFlowElement',
|
|
@@ -123527,14 +123567,6 @@ const createComponentNode = ({ tag, attributes, children, startPosition, endPosi
|
|
|
123527
123567
|
end: endPosition?.end ?? startPosition?.end,
|
|
123528
123568
|
},
|
|
123529
123569
|
});
|
|
123530
|
-
// The promoted node takes over the html node's position, so it also takes over the
|
|
123531
|
-
// coordinate space that position belongs to.
|
|
123532
|
-
const substituteNodeWithMdxNode = (parent, index, mdxNode) => {
|
|
123533
|
-
const replacedSource = parent.children[index]?.data?.reparseSource;
|
|
123534
|
-
if (replacedSource)
|
|
123535
|
-
stampReparseSource([mdxNode], replacedSource);
|
|
123536
|
-
parent.children.splice(index, 1, mdxNode);
|
|
123537
|
-
};
|
|
123538
123570
|
/**
|
|
123539
123571
|
* Transform PascalCase HTML nodes into mdxJsxFlowElement nodes.
|
|
123540
123572
|
*
|
|
@@ -123633,7 +123665,7 @@ function promoteComponentBlocks(tree, safeMode, source) {
|
|
|
123633
123665
|
? positionEndingAtConsumed(node.position, value, leadingWhitespace + openingTagEnd, source)
|
|
123634
123666
|
: node.position,
|
|
123635
123667
|
});
|
|
123636
|
-
|
|
123668
|
+
replaceInheritingReparseSource(parent, index, [componentNode]);
|
|
123637
123669
|
if (remainingContent) {
|
|
123638
123670
|
parseSibling(parent, index, remainingContent, safeMode, promoted);
|
|
123639
123671
|
}
|
|
@@ -123684,7 +123716,7 @@ function promoteComponentBlocks(tree, safeMode, source) {
|
|
|
123684
123716
|
startPosition: node.position,
|
|
123685
123717
|
endPosition,
|
|
123686
123718
|
});
|
|
123687
|
-
|
|
123719
|
+
replaceInheritingReparseSource(parent, index, [componentNode]);
|
|
123688
123720
|
// The unwrap reparented the children out of their paragraph, so re-walk them
|
|
123689
123721
|
// since the children HTML may contain promotable syntax (e.g. `{…}`-attr tags)
|
|
123690
123722
|
if (unwrappedSoleParagraph) {
|
|
@@ -126173,7 +126205,7 @@ const parseApiHeaderTitle = (text) => {
|
|
|
126173
126205
|
* Transform a magicBlock node into final MDAST nodes.
|
|
126174
126206
|
*/
|
|
126175
126207
|
function transformMagicBlock(blockType, data, rawValue, options = {}) {
|
|
126176
|
-
const { compatibilityMode = false, hardBreaks = true } = options;
|
|
126208
|
+
const { compatibilityMode = false, hardBreaks = true, safeMode = false } = options;
|
|
126177
126209
|
// Handle empty data by returning placeholder nodes for known block types
|
|
126178
126210
|
// This allows the editor to show appropriate placeholder UI instead of nothing
|
|
126179
126211
|
if (Object.keys(data).length < 1) {
|
|
@@ -126391,7 +126423,7 @@ function transformMagicBlock(blockType, data, rawValue, options = {}) {
|
|
|
126391
126423
|
wrapPinnedBlocks({
|
|
126392
126424
|
data: {
|
|
126393
126425
|
hName: 'html-block',
|
|
126394
|
-
hProperties: { html: htmlJson.html, runScripts: compatibilityMode },
|
|
126426
|
+
hProperties: { html: htmlJson.html, runScripts: compatibilityMode, safeMode },
|
|
126395
126427
|
},
|
|
126396
126428
|
type: 'html-block',
|
|
126397
126429
|
}, data),
|
|
@@ -126532,6 +126564,7 @@ const magicBlockTransformer = (options = {}) => tree => {
|
|
|
126532
126564
|
|
|
126533
126565
|
|
|
126534
126566
|
|
|
126567
|
+
|
|
126535
126568
|
// `<HTMLBlock …>{`…`}</HTMLBlock>` embedded inside a raw HTML block (e.g. a
|
|
126536
126569
|
// single-line `<div>…</div>`). CommonMark slurps the whole div as one `html`
|
|
126537
126570
|
// node, so the tokenizer never sees the HTMLBlock — we recover it here.
|
|
@@ -126638,7 +126671,8 @@ const mdxishHtmlBlocks = () => tree => {
|
|
|
126638
126671
|
return;
|
|
126639
126672
|
const exprChild = element.children.find(child => child.type === 'mdxFlowExpression' || child.type === 'mdxTextExpression');
|
|
126640
126673
|
const openingTagIndent = (element.position?.start.column ?? 1) - 1;
|
|
126641
|
-
|
|
126674
|
+
const htmlBlock = createHtmlBlockNode(formatHtmlForMdxish(extractTemplateLiteral(exprChild?.value), openingTagIndent), element.position, toRunScripts(jsxAttr(element, 'runScripts')), jsxAttr(element, 'safeMode'));
|
|
126675
|
+
replaceInheritingReparseSource(parent, index, [htmlBlock]);
|
|
126642
126676
|
});
|
|
126643
126677
|
// Shape 2: raw HTML blob.
|
|
126644
126678
|
visit(tree, 'html', (node, index, parent) => {
|
|
@@ -126646,7 +126680,7 @@ const mdxishHtmlBlocks = () => tree => {
|
|
|
126646
126680
|
return;
|
|
126647
126681
|
const replacement = splitRawHtmlBlocks(node);
|
|
126648
126682
|
if (replacement)
|
|
126649
|
-
parent
|
|
126683
|
+
replaceInheritingReparseSource(parent, index, replacement);
|
|
126650
126684
|
});
|
|
126651
126685
|
};
|
|
126652
126686
|
/* harmony default export */ const mdxish_html_blocks = (mdxishHtmlBlocks);
|
|
@@ -126733,6 +126767,7 @@ const hasOnlyWidthAttributes = (cell) => {
|
|
|
126733
126767
|
|
|
126734
126768
|
|
|
126735
126769
|
|
|
126770
|
+
|
|
126736
126771
|
function toImageAlign(value) {
|
|
126737
126772
|
if (value === 'left' || value === 'center' || value === 'right') {
|
|
126738
126773
|
return value;
|
|
@@ -126948,6 +126983,15 @@ const transformAnchor = (jsx) => {
|
|
|
126948
126983
|
position: jsx.position,
|
|
126949
126984
|
};
|
|
126950
126985
|
};
|
|
126986
|
+
/**
|
|
126987
|
+
* Parses an image caption's markdown. The caption is re-parsed on its own, so the
|
|
126988
|
+
* children's positions index into it rather than the document.
|
|
126989
|
+
*/
|
|
126990
|
+
const parseCaptionChildren = (caption) => {
|
|
126991
|
+
const { children } = lib_mdast(caption);
|
|
126992
|
+
stampReparseSource(children, caption);
|
|
126993
|
+
return children;
|
|
126994
|
+
};
|
|
126951
126995
|
/**
|
|
126952
126996
|
* Transforms an `<Image />` JSX element into an image-block MDAST node.
|
|
126953
126997
|
* Normalizes attributes (align, border, width→sizing) and parses caption markdown into children.
|
|
@@ -126978,7 +127022,7 @@ const transformImage = (jsx) => {
|
|
|
126978
127022
|
alt,
|
|
126979
127023
|
border: toBool(border),
|
|
126980
127024
|
caption,
|
|
126981
|
-
children: caption ?
|
|
127025
|
+
children: caption ? parseCaptionChildren(caption) : [],
|
|
126982
127026
|
className,
|
|
126983
127027
|
framed: toBool(framed),
|
|
126984
127028
|
height: height !== undefined ? String(height) : undefined,
|
|
@@ -127315,8 +127359,7 @@ const mdxishJsxToMdast = () => tree => {
|
|
|
127315
127359
|
const newNode = transformer(node);
|
|
127316
127360
|
if (!newNode)
|
|
127317
127361
|
return;
|
|
127318
|
-
|
|
127319
|
-
parent.children[index] = newNode;
|
|
127362
|
+
replaceInheritingReparseSource(parent, index, [newNode]);
|
|
127320
127363
|
});
|
|
127321
127364
|
// Inline JSX components (Anchor)
|
|
127322
127365
|
visit(tree, 'mdxJsxTextElement', (node, index, parent) => {
|
|
@@ -128172,7 +128215,6 @@ function loadComponents() {
|
|
|
128172
128215
|
|
|
128173
128216
|
|
|
128174
128217
|
|
|
128175
|
-
|
|
128176
128218
|
|
|
128177
128219
|
|
|
128178
128220
|
const defaultTransformers = [
|
|
@@ -128328,8 +128370,7 @@ function mdxish(mdContent, opts = {}) {
|
|
|
128328
128370
|
.use(rehypeMdxishComponents, {
|
|
128329
128371
|
components,
|
|
128330
128372
|
processMarkdown: (markdown) => mdxish(markdown, opts),
|
|
128331
|
-
})
|
|
128332
|
-
.use(safeMode ? enforceSafeModeHtmlBlocks : undefined); // Force safeMode on every HTMLBlock; runs last so every producer is covered
|
|
128373
|
+
});
|
|
128333
128374
|
const vfile = new VFile({ value: parserReadyContent });
|
|
128334
128375
|
const mdast = processor.parse(parserReadyContent);
|
|
128335
128376
|
const hast = processor.runSync(mdast, vfile);
|
|
@@ -129405,7 +129446,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"*":["about","acceptCharset","accessK
|
|
|
129405
129446
|
/******/ // startup
|
|
129406
129447
|
/******/ // Load entry module and return exports
|
|
129407
129448
|
/******/ // This entry module used 'module' so it can't be inlined
|
|
129408
|
-
/******/ let __webpack_exports__ = __webpack_require__(
|
|
129449
|
+
/******/ let __webpack_exports__ = __webpack_require__(1186);
|
|
129409
129450
|
/******/ module.exports = __webpack_exports__;
|
|
129410
129451
|
/******/
|
|
129411
129452
|
/******/ })()
|