@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
package/dist/main.js
CHANGED
|
@@ -11423,7 +11423,7 @@ module.exports = function () {
|
|
|
11423
11423
|
|
|
11424
11424
|
/***/ },
|
|
11425
11425
|
|
|
11426
|
-
/***/
|
|
11426
|
+
/***/ 8846
|
|
11427
11427
|
(module, __webpack_exports__, __webpack_require__) {
|
|
11428
11428
|
|
|
11429
11429
|
"use strict";
|
|
@@ -12156,9 +12156,9 @@ const HTMLBlock = ({ children = '', html: htmlProp, runScripts, safeMode: safeMo
|
|
|
12156
12156
|
const safeMode = typeof safeModeRaw !== 'boolean' ? safeModeRaw === 'true' : safeModeRaw;
|
|
12157
12157
|
const [cleanedHtml, exec] = extractScripts(html);
|
|
12158
12158
|
(0,external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.useEffect)(() => {
|
|
12159
|
-
if (typeof window !== 'undefined' && typeof runScripts === 'boolean' && runScripts
|
|
12159
|
+
if (typeof window !== 'undefined' && typeof runScripts === 'boolean' && runScripts)
|
|
12160
12160
|
exec();
|
|
12161
|
-
}, [runScripts,
|
|
12161
|
+
}, [runScripts, exec]);
|
|
12162
12162
|
if (nonStringChildren) {
|
|
12163
12163
|
// Fail soft: a non-string child (e.g. JSX that wasn't serialized back to a
|
|
12164
12164
|
// raw string) should never throw, so render the child nodes directly
|
|
@@ -54965,18 +54965,53 @@ function evaluate(source, scope = {}) {
|
|
|
54965
54965
|
return new Function(...names, `return (${source})`)(...values);
|
|
54966
54966
|
}
|
|
54967
54967
|
/**
|
|
54968
|
-
*
|
|
54969
|
-
*
|
|
54970
|
-
*
|
|
54968
|
+
* Width each container prefix adds back per line of `value`, aligned from the line end since a
|
|
54969
|
+
* tab in the prefix is expanded to spaces in `value`. None (a verbatim slice) when the source
|
|
54970
|
+
* is missing or doesn't line up.
|
|
54971
54971
|
*/
|
|
54972
|
-
const
|
|
54973
|
-
const
|
|
54974
|
-
const
|
|
54975
|
-
|
|
54976
|
-
|
|
54977
|
-
|
|
54978
|
-
|
|
54979
|
-
|
|
54972
|
+
const containerPrefixWidths = (valueLines, source, position) => {
|
|
54973
|
+
const sourceLines = source?.slice(position.start.offset, position.end.offset).split('\n');
|
|
54974
|
+
const linesUp = sourceLines?.length === valueLines.length &&
|
|
54975
|
+
sourceLines.every((line, i) => line.endsWith(valueLines[i].trimStart()));
|
|
54976
|
+
return valueLines.map((line, i) => (linesUp ? sourceLines[i].length - line.length : 0));
|
|
54977
|
+
};
|
|
54978
|
+
/**
|
|
54979
|
+
* Maps offsets in a node's `value` to points in `source`. Containers strip a prefix from every
|
|
54980
|
+
* continuation line of `value`, so a plain offset shift drifts by line (CX-4028).
|
|
54981
|
+
*/
|
|
54982
|
+
const createValueToSourceMapper = (position, value, source) => {
|
|
54983
|
+
if (position?.start.offset === undefined)
|
|
54984
|
+
return null;
|
|
54985
|
+
const { start } = position;
|
|
54986
|
+
const valueLines = value.split('\n');
|
|
54987
|
+
const prefixWidths = containerPrefixWidths(valueLines, source, position);
|
|
54988
|
+
const lines = [];
|
|
54989
|
+
let valueStart = 0;
|
|
54990
|
+
let sourceStart = start.offset;
|
|
54991
|
+
valueLines.forEach((line, i) => {
|
|
54992
|
+
lines.push({ prefixWidth: prefixWidths[i], sourceStart, valueStart });
|
|
54993
|
+
valueStart += line.length + 1;
|
|
54994
|
+
sourceStart += prefixWidths[i] + line.length + 1;
|
|
54995
|
+
});
|
|
54996
|
+
return valueOffset => {
|
|
54997
|
+
// Binary search: a large table maps one point per node.
|
|
54998
|
+
let low = 0;
|
|
54999
|
+
let high = lines.length - 1;
|
|
55000
|
+
while (low < high) {
|
|
55001
|
+
const mid = Math.ceil((low + high) / 2);
|
|
55002
|
+
if (lines[mid].valueStart <= valueOffset)
|
|
55003
|
+
low = mid;
|
|
55004
|
+
else
|
|
55005
|
+
high = mid - 1;
|
|
55006
|
+
}
|
|
55007
|
+
const { prefixWidth, sourceStart: lineSourceStart, valueStart: lineValueStart } = lines[low];
|
|
55008
|
+
// Clamped: an expanded tab can make a leading-whitespace offset fall before the line.
|
|
55009
|
+
const sourceColumn = Math.max(0, prefixWidth + valueOffset - lineValueStart);
|
|
55010
|
+
return {
|
|
55011
|
+
line: start.line + low,
|
|
55012
|
+
column: (low === 0 ? start.column : 1) + sourceColumn,
|
|
55013
|
+
offset: lineSourceStart + sourceColumn,
|
|
55014
|
+
};
|
|
54980
55015
|
};
|
|
54981
55016
|
};
|
|
54982
55017
|
/**
|
|
@@ -55639,7 +55674,9 @@ const processBlockquote = (node, index, parent, isMdxish = false) => {
|
|
|
55639
55674
|
}
|
|
55640
55675
|
Object.assign(node, {
|
|
55641
55676
|
type: NodeTypes.callout,
|
|
55677
|
+
// Keep the blockquote's data, e.g. the `reparseSource` its positions index into.
|
|
55642
55678
|
data: {
|
|
55679
|
+
...node.data,
|
|
55643
55680
|
hName: 'Callout',
|
|
55644
55681
|
hProperties: {
|
|
55645
55682
|
icon,
|
|
@@ -55672,14 +55709,55 @@ const calloutTransformer = ({ isMdxish = false } = {}) => {
|
|
|
55672
55709
|
};
|
|
55673
55710
|
/* harmony default export */ const callouts = (calloutTransformer);
|
|
55674
55711
|
|
|
55712
|
+
;// ./processor/transform/mdxish/reparse-source.ts
|
|
55713
|
+
/**
|
|
55714
|
+
* Mark re-parsed subtree roots with the string their positions index into, so consumers
|
|
55715
|
+
* slicing by offset use the right source (see `Data.reparseSource`). Only roots are
|
|
55716
|
+
* stamped; descendants resolve via their nearest stamped ancestor. Roots a deeper
|
|
55717
|
+
* re-parse already stamped keep their own string.
|
|
55718
|
+
*/
|
|
55719
|
+
const stampReparseSource = (roots, reparseSource) => {
|
|
55720
|
+
roots.forEach(root => {
|
|
55721
|
+
if (!root.data?.reparseSource)
|
|
55722
|
+
root.data = { ...root.data, reparseSource };
|
|
55723
|
+
});
|
|
55724
|
+
};
|
|
55725
|
+
/**
|
|
55726
|
+
* Splice `replacements` over `parent.children[index]`. They take over the replaced node's
|
|
55727
|
+
* position, so they also take over the coordinate space that position indexes into.
|
|
55728
|
+
*/
|
|
55729
|
+
const replaceInheritingReparseSource = (parent, index, replacements) => {
|
|
55730
|
+
const replacedSource = parent.children[index]?.data?.reparseSource;
|
|
55731
|
+
if (replacedSource)
|
|
55732
|
+
stampReparseSource(replacements, replacedSource);
|
|
55733
|
+
parent.children.splice(index, 1, ...replacements);
|
|
55734
|
+
};
|
|
55735
|
+
/**
|
|
55736
|
+
* The string `node`'s offsets index into: the nearest stamp on it or an ancestor, else the
|
|
55737
|
+
* document source.
|
|
55738
|
+
*/
|
|
55739
|
+
const resolveReparseSource = (node, ancestors, documentSource) => {
|
|
55740
|
+
if (node.data?.reparseSource)
|
|
55741
|
+
return node.data.reparseSource;
|
|
55742
|
+
for (let i = ancestors.length - 1; i >= 0; i -= 1) {
|
|
55743
|
+
const { reparseSource } = ancestors[i].data ?? {};
|
|
55744
|
+
if (reparseSource)
|
|
55745
|
+
return reparseSource;
|
|
55746
|
+
}
|
|
55747
|
+
return documentSource;
|
|
55748
|
+
};
|
|
55749
|
+
|
|
55675
55750
|
;// ./processor/transform/code-tabs.ts
|
|
55676
55751
|
|
|
55677
55752
|
|
|
55753
|
+
|
|
55678
55754
|
const isCode = (node) => node?.type === 'code';
|
|
55679
55755
|
const codeTabsTransformer = ({ copyButtons } = {}) => (tree) => {
|
|
55680
55756
|
visit(tree, 'code', (node) => {
|
|
55681
55757
|
const { lang, meta, value } = node;
|
|
55682
55758
|
node.data = {
|
|
55759
|
+
// Ensure positions are passed through
|
|
55760
|
+
...node.data,
|
|
55683
55761
|
hProperties: { lang, meta, value, copyButtons },
|
|
55684
55762
|
};
|
|
55685
55763
|
});
|
|
@@ -55726,6 +55804,9 @@ const codeTabsTransformer = ({ copyButtons } = {}) => (tree) => {
|
|
|
55726
55804
|
end: children[children.length - 1].position.end,
|
|
55727
55805
|
},
|
|
55728
55806
|
};
|
|
55807
|
+
// Adjacent siblings share a coordinate space, so the wrapper takes the first block's.
|
|
55808
|
+
if (node.data?.reparseSource)
|
|
55809
|
+
stampReparseSource([codeTabs], node.data.reparseSource);
|
|
55729
55810
|
parent.children.splice(index, children.length, codeTabs);
|
|
55730
55811
|
});
|
|
55731
55812
|
return tree;
|
|
@@ -80108,6 +80189,7 @@ const walkTags = (html, handlers) => {
|
|
|
80108
80189
|
};
|
|
80109
80190
|
|
|
80110
80191
|
;// ./processor/transform/mdxish/tables/utils.ts
|
|
80192
|
+
|
|
80111
80193
|
const tableTags = new Set([
|
|
80112
80194
|
'thead',
|
|
80113
80195
|
'tbody',
|
|
@@ -80126,6 +80208,9 @@ const tableTags = new Set([
|
|
|
80126
80208
|
const unwrapParagraphNodes = (children) => {
|
|
80127
80209
|
return children.flatMap(child => {
|
|
80128
80210
|
if (child.type === 'paragraph' && 'children' in child && Array.isArray(child.children)) {
|
|
80211
|
+
// The unwrap drops a stamped root, so its children inherit that coordinate space.
|
|
80212
|
+
if (child.data?.reparseSource)
|
|
80213
|
+
stampReparseSource(child.children, child.data.reparseSource);
|
|
80129
80214
|
return child.children;
|
|
80130
80215
|
}
|
|
80131
80216
|
return [child];
|
|
@@ -80721,9 +80806,10 @@ const findTableRanges = (html) => {
|
|
|
80721
80806
|
* The surrounding raw HTML (the wrapper's open/close tags) would be re-nested
|
|
80722
80807
|
* around the parsed tables by rehype-raw.
|
|
80723
80808
|
*
|
|
80724
|
-
* Returns null when there is no wrapped table to extract.
|
|
80809
|
+
* Returns null when there is no wrapped table to extract. `source` is the string the node's
|
|
80810
|
+
* positions index into, so the parts' positions survive stripped container prefixes.
|
|
80725
80811
|
*/
|
|
80726
|
-
const splitHtmlWithNestedTables = (node) => {
|
|
80812
|
+
const splitHtmlWithNestedTables = (node, source) => {
|
|
80727
80813
|
const { value } = node;
|
|
80728
80814
|
// This is a top-level table, so we don't need to split it
|
|
80729
80815
|
if (TOP_LEVEL_TABLE_TAG_RE.test(value))
|
|
@@ -80736,13 +80822,11 @@ const splitHtmlWithNestedTables = (node) => {
|
|
|
80736
80822
|
const ranges = findTableRanges(value);
|
|
80737
80823
|
if (ranges.length === 0)
|
|
80738
80824
|
return null;
|
|
80739
|
-
const
|
|
80825
|
+
const toSourcePoint = createValueToSourceMapper(node.position, value, source);
|
|
80740
80826
|
const sliceToHtml = (from, to) => ({
|
|
80741
80827
|
type: 'html',
|
|
80742
80828
|
value: value.slice(from, to),
|
|
80743
|
-
...(
|
|
80744
|
-
position: { start: pointAfter(base, value.slice(0, from)), end: pointAfter(base, value.slice(0, to)) },
|
|
80745
|
-
}),
|
|
80829
|
+
...(toSourcePoint && { position: { start: toSourcePoint(from), end: toSourcePoint(to) } }),
|
|
80746
80830
|
});
|
|
80747
80831
|
const parts = [];
|
|
80748
80832
|
let cursor = 0;
|
|
@@ -80777,6 +80861,8 @@ const splitHtmlWithNestedTables = (node) => {
|
|
|
80777
80861
|
|
|
80778
80862
|
|
|
80779
80863
|
|
|
80864
|
+
|
|
80865
|
+
|
|
80780
80866
|
|
|
80781
80867
|
|
|
80782
80868
|
|
|
@@ -80829,7 +80915,7 @@ const tableRepairs = [
|
|
|
80829
80915
|
* The plugins in the processor allows parsing markdown & special syntax inside the table cells
|
|
80830
80916
|
* After parsing, we need to update the node positions
|
|
80831
80917
|
*/
|
|
80832
|
-
const parseTableNode = (processor, node, repair) => {
|
|
80918
|
+
const parseTableNode = (processor, node, source, repair) => {
|
|
80833
80919
|
let parsed;
|
|
80834
80920
|
try {
|
|
80835
80921
|
parsed = processor.runSync(processor.parse(node.value));
|
|
@@ -80843,19 +80929,18 @@ const parseTableNode = (processor, node, repair) => {
|
|
|
80843
80929
|
if (repair) {
|
|
80844
80930
|
remapPositionsThroughLayers(parsed, repair.originalSource, repair.layers);
|
|
80845
80931
|
}
|
|
80846
|
-
// The subparser produces positions relative to `node.value`;
|
|
80847
|
-
// the outer
|
|
80848
|
-
const
|
|
80849
|
-
|
|
80932
|
+
// The subparser produces positions relative to `node.value`; map them into
|
|
80933
|
+
// the outer source so consumers can slice it.
|
|
80934
|
+
const toSourcePoint = createValueToSourceMapper(node.position, repair?.originalSource ?? node.value, source);
|
|
80935
|
+
if (!toSourcePoint)
|
|
80936
|
+
return parsed;
|
|
80850
80937
|
visit(parsed, child => {
|
|
80851
|
-
if (child.position
|
|
80852
|
-
|
|
80853
|
-
|
|
80854
|
-
|
|
80855
|
-
|
|
80856
|
-
|
|
80857
|
-
child.position.end.line += baseLine;
|
|
80858
|
-
}
|
|
80938
|
+
if (!child.position)
|
|
80939
|
+
return;
|
|
80940
|
+
child.position = {
|
|
80941
|
+
start: toSourcePoint(child.position.start.offset ?? 0),
|
|
80942
|
+
end: toSourcePoint(child.position.end.offset ?? 0),
|
|
80943
|
+
};
|
|
80859
80944
|
});
|
|
80860
80945
|
return parsed;
|
|
80861
80946
|
};
|
|
@@ -80885,12 +80970,10 @@ const hasFlowContent = (nodes) => {
|
|
|
80885
80970
|
return nodes.some(node => !phrasing(node) && node.type !== 'paragraph');
|
|
80886
80971
|
};
|
|
80887
80972
|
/**
|
|
80888
|
-
* Process a Table node: re-parse text-only cell content, then
|
|
80889
|
-
* a markdown table (phrasing-only) or keep as JSX <Table> (has flow content).
|
|
80973
|
+
* Process a Table node: re-parse text-only cell content, then return it as
|
|
80974
|
+
* a markdown table (phrasing-only) or keep it as JSX <Table> (has flow content).
|
|
80890
80975
|
*/
|
|
80891
|
-
const processTableNode = (node,
|
|
80892
|
-
if (node.name !== 'Table' && node.name !== 'table')
|
|
80893
|
-
return;
|
|
80976
|
+
const processTableNode = (node, documentPosition) => {
|
|
80894
80977
|
const position = documentPosition ?? node.position;
|
|
80895
80978
|
const { align: alignAttr } = getAttrs(node);
|
|
80896
80979
|
const align = Array.isArray(alignAttr) ? alignAttr : null;
|
|
@@ -80917,6 +81000,8 @@ const processTableNode = (node, index, parent, documentPosition) => {
|
|
|
80917
81000
|
try {
|
|
80918
81001
|
const parsed = tableNodeProcessor.runSync(tableNodeProcessor.parse(textContent));
|
|
80919
81002
|
if (parsed.children.length > 0) {
|
|
81003
|
+
// Positions index into the extracted text rather than the table source (CX-4004).
|
|
81004
|
+
stampReparseSource(parsed.children, textContent);
|
|
80920
81005
|
cell.children = parsed.children;
|
|
80921
81006
|
if (hasFlowContent(parsed.children)) {
|
|
80922
81007
|
tableHasFlowContent = true;
|
|
@@ -80959,11 +81044,7 @@ const processTableNode = (node, index, parent, documentPosition) => {
|
|
|
80959
81044
|
: unwrapParagraphNodes(el.children);
|
|
80960
81045
|
el.children = removeWhitespaceOnlyTextNodes(unwrapped);
|
|
80961
81046
|
});
|
|
80962
|
-
|
|
80963
|
-
...node,
|
|
80964
|
-
position,
|
|
80965
|
-
};
|
|
80966
|
-
return;
|
|
81047
|
+
return { ...node, position };
|
|
80967
81048
|
}
|
|
80968
81049
|
// All cells are phrasing-only — convert to markdown table
|
|
80969
81050
|
const children = [];
|
|
@@ -81041,7 +81122,7 @@ const processTableNode = (node, index, parent, documentPosition) => {
|
|
|
81041
81122
|
const alignArray = align && columnCount > 0
|
|
81042
81123
|
? align.slice(0, columnCount).concat(new Array(Math.max(0, columnCount - align.length)).fill(null))
|
|
81043
81124
|
: new Array(columnCount).fill(null);
|
|
81044
|
-
|
|
81125
|
+
return {
|
|
81045
81126
|
align: alignArray,
|
|
81046
81127
|
type: 'table',
|
|
81047
81128
|
position,
|
|
@@ -81049,14 +81130,13 @@ const processTableNode = (node, index, parent, documentPosition) => {
|
|
|
81049
81130
|
// Remember the author's spelling so the serializer can write `<table>` back instead of `<Table>`
|
|
81050
81131
|
...(node.name === 'table' && { data: { lowercaseTable: true } }),
|
|
81051
81132
|
};
|
|
81052
|
-
parent.children[index] = mdNode;
|
|
81053
81133
|
};
|
|
81054
81134
|
/**
|
|
81055
81135
|
* Apply `tableRepairs` cumulatively, re-parsing after every change and stopping
|
|
81056
81136
|
* once the accumulated result parses. Each layer's inserts are relative to the
|
|
81057
81137
|
* string that repair received, so they stay ordered for position remapping.
|
|
81058
81138
|
*/
|
|
81059
|
-
const repairAndReparse = (node) => {
|
|
81139
|
+
const repairAndReparse = (node, source) => {
|
|
81060
81140
|
let repairedValue = node.value;
|
|
81061
81141
|
const layers = [];
|
|
81062
81142
|
let parsed;
|
|
@@ -81066,11 +81146,45 @@ const repairAndReparse = (node) => {
|
|
|
81066
81146
|
return false;
|
|
81067
81147
|
repairedValue = value;
|
|
81068
81148
|
layers.push(inserts);
|
|
81069
|
-
parsed = parseTableNode(tableNodeProcessor, { ...node, value: repairedValue },
|
|
81149
|
+
parsed = parseTableNode(tableNodeProcessor, { ...node, value: repairedValue }, source, {
|
|
81150
|
+
layers,
|
|
81151
|
+
originalSource: node.value,
|
|
81152
|
+
});
|
|
81070
81153
|
return Boolean(parsed);
|
|
81071
81154
|
});
|
|
81072
81155
|
return parsed;
|
|
81073
81156
|
};
|
|
81157
|
+
/**
|
|
81158
|
+
* Re-parse a table html node and replace it with a markdown / JSX table, or the
|
|
81159
|
+
* fallback parse's fragments for a lowercase table mdxjs rejects.
|
|
81160
|
+
*/
|
|
81161
|
+
const replaceTableHtml = (node, index, parent, source) => {
|
|
81162
|
+
// Because the processor uses remarkMdx, it is stricter in what it accepts
|
|
81163
|
+
// and only accepts valid MDX syntax in the table node. To get around that,
|
|
81164
|
+
// fall back to the cumulative repairs when the first parse fails.
|
|
81165
|
+
const parsed = parseTableNode(tableNodeProcessor, node, source) ?? repairAndReparse(node, source);
|
|
81166
|
+
if (parsed) {
|
|
81167
|
+
// If the table is parsed successfully, we can now process it further
|
|
81168
|
+
// to build on the markdown / JSX table
|
|
81169
|
+
visit(parsed, isMDXElement, (tableNode) => {
|
|
81170
|
+
if (tableNode.name !== 'Table' && tableNode.name !== 'table')
|
|
81171
|
+
return undefined;
|
|
81172
|
+
replaceInheritingReparseSource(parent, index, [processTableNode(tableNode, node.position)]);
|
|
81173
|
+
return (/* inlined export .EXIT */false);
|
|
81174
|
+
});
|
|
81175
|
+
}
|
|
81176
|
+
else if (node.value.startsWith('<table')) {
|
|
81177
|
+
// If the parsing still fails, give an opportunity to the fallback parser
|
|
81178
|
+
// without remarkMdx to process lowercase tables as it's likely to not
|
|
81179
|
+
// have needed MDX parsing anyway
|
|
81180
|
+
const fallback = parseTableNode(fallbackTableNodeProcessor, node, source);
|
|
81181
|
+
if (!fallback || fallback.children.length <= 1)
|
|
81182
|
+
return;
|
|
81183
|
+
replaceInheritingReparseSource(parent, index, fallback.children);
|
|
81184
|
+
}
|
|
81185
|
+
// Otherwise, there's no point in trying to parse the table content further
|
|
81186
|
+
// More repairs are needed in that case
|
|
81187
|
+
};
|
|
81074
81188
|
/**
|
|
81075
81189
|
* Converts JSX Table elements to markdown table nodes and re-parses markdown in cells.
|
|
81076
81190
|
*
|
|
@@ -81082,24 +81196,26 @@ const repairAndReparse = (node) => {
|
|
|
81082
81196
|
* When cell content contains block-level nodes (callouts, code blocks, etc.), the table
|
|
81083
81197
|
* is kept as a JSX <Table> element so that remarkRehype can properly handle the flow content.
|
|
81084
81198
|
*/
|
|
81085
|
-
const mdxishTables = () => tree => {
|
|
81199
|
+
const mdxishTables = () => (tree, file) => {
|
|
81200
|
+
// Positions index into the document unless a re-parse stamped another source.
|
|
81201
|
+
const documentSource = file?.value ? String(file.value) : undefined;
|
|
81086
81202
|
// Pre-pass: lift `<table>`s wrapped in a raw HTML block out into their own
|
|
81087
81203
|
// html nodes so the main pass below treats them like top-level tables.
|
|
81088
|
-
|
|
81089
|
-
const
|
|
81090
|
-
if (
|
|
81204
|
+
visitParents(tree, 'html', (node, ancestors) => {
|
|
81205
|
+
const parent = ancestors[ancestors.length - 1];
|
|
81206
|
+
if (!parent)
|
|
81091
81207
|
return;
|
|
81092
|
-
const parts = splitHtmlWithNestedTables(node);
|
|
81208
|
+
const parts = splitHtmlWithNestedTables(node, resolveReparseSource(node, ancestors, documentSource));
|
|
81093
81209
|
if (!parts)
|
|
81094
81210
|
return;
|
|
81095
81211
|
// The inserted parts can't re-trigger a split (table parts start with
|
|
81096
81212
|
// `<table`; the wrapper slices hold no table), so plain in-place splicing
|
|
81097
81213
|
// visits each once without looping.
|
|
81098
|
-
parent.children.
|
|
81214
|
+
replaceInheritingReparseSource(parent, parent.children.indexOf(node), parts);
|
|
81099
81215
|
});
|
|
81100
|
-
|
|
81101
|
-
const
|
|
81102
|
-
if (
|
|
81216
|
+
visitParents(tree, 'html', (node, ancestors) => {
|
|
81217
|
+
const parent = ancestors[ancestors.length - 1];
|
|
81218
|
+
if (!parent)
|
|
81103
81219
|
return;
|
|
81104
81220
|
if (!node.value.startsWith('<Table') && !node.value.startsWith('<table'))
|
|
81105
81221
|
return;
|
|
@@ -81107,33 +81223,8 @@ const mdxishTables = () => tree => {
|
|
|
81107
81223
|
// paragraph. Leave them untouched so rehype-raw can reassemble the table.
|
|
81108
81224
|
if (parent.type === 'paragraph')
|
|
81109
81225
|
return;
|
|
81110
|
-
|
|
81111
|
-
// and only accepts valid MDX syntax in the table node. To get around that,
|
|
81112
|
-
// fall back to the cumulative repairs when the first parse fails.
|
|
81113
|
-
const parsed = parseTableNode(tableNodeProcessor, node) ?? repairAndReparse(node);
|
|
81114
|
-
if (parsed) {
|
|
81115
|
-
// If the table is parsed successfully, we can now process it further
|
|
81116
|
-
// to build on the markdown / JSX table
|
|
81117
|
-
visit(parsed, isMDXElement, (tableNode) => {
|
|
81118
|
-
if (tableNode.name !== 'Table' && tableNode.name !== 'table')
|
|
81119
|
-
return undefined;
|
|
81120
|
-
processTableNode(tableNode, index, parent, node.position);
|
|
81121
|
-
return (/* inlined export .EXIT */false);
|
|
81122
|
-
});
|
|
81123
|
-
}
|
|
81124
|
-
else if (node.value.startsWith('<table')) {
|
|
81125
|
-
// If the parsing still fails, give an opportunity to the fallback parser
|
|
81126
|
-
// without remarkMdx to process lowercase tables as it's likely to not
|
|
81127
|
-
// have needed MDX parsing anyway
|
|
81128
|
-
const fallback = parseTableNode(fallbackTableNodeProcessor, node);
|
|
81129
|
-
if (!fallback || fallback.children.length <= 1)
|
|
81130
|
-
return;
|
|
81131
|
-
parent.children.splice(index, 1, ...fallback.children);
|
|
81132
|
-
}
|
|
81133
|
-
// Otherwise, there's no point in trying to parse the table content further
|
|
81134
|
-
// More repairs are needed in that case
|
|
81226
|
+
replaceTableHtml(node, parent.children.indexOf(node), parent, resolveReparseSource(node, ancestors, documentSource));
|
|
81135
81227
|
});
|
|
81136
|
-
return tree;
|
|
81137
81228
|
};
|
|
81138
81229
|
/* harmony default export */ const mdxish_tables = (mdxishTables);
|
|
81139
81230
|
|
|
@@ -103888,32 +103979,6 @@ const mdxComponentHandlers = {
|
|
|
103888
103979
|
[NodeTypes.htmlBlock]: htmlBlockHandler,
|
|
103889
103980
|
};
|
|
103890
103981
|
|
|
103891
|
-
;// ./processor/plugin/safe-mode-html-blocks.ts
|
|
103892
|
-
|
|
103893
|
-
|
|
103894
|
-
/**
|
|
103895
|
-
* Whether a tag name renders through the `HTMLBlock` component. Mirrors the
|
|
103896
|
-
* separator-agnostic, case-insensitive lookup in `getComponentName` and the
|
|
103897
|
-
* rehype-react component map, so `html-block`, `HTMLBlock`, `HtmlBlock` and
|
|
103898
|
-
* `htmlblock` all match.
|
|
103899
|
-
*/
|
|
103900
|
-
const isHtmlBlockTag = (tagName) => toPascalCase(tagName).toLowerCase() === 'htmlblock';
|
|
103901
|
-
/**
|
|
103902
|
-
* Forces `safeMode` on every element that renders through `HTMLBlock` so it is
|
|
103903
|
-
* shown as escaped text instead of injected.
|
|
103904
|
-
*
|
|
103905
|
-
* Runs last, so it sees every producer of the element — `[block:html]`,
|
|
103906
|
-
* `<HTMLBlock>` with a template body or an `html` attribute, and a literal
|
|
103907
|
-
* `<html-block>` — and it is unconditional so an author-supplied
|
|
103908
|
-
* `safeMode="false"` can't opt out.
|
|
103909
|
-
*/
|
|
103910
|
-
const enforceSafeModeHtmlBlocks = () => tree => {
|
|
103911
|
-
visit(tree, 'element', node => {
|
|
103912
|
-
if (isHtmlBlockTag(node.tagName))
|
|
103913
|
-
node.properties.safeMode = 'true';
|
|
103914
|
-
});
|
|
103915
|
-
};
|
|
103916
|
-
|
|
103917
103982
|
;// ./processor/transform/mdxish/anchor-to-jsx.ts
|
|
103918
103983
|
|
|
103919
103984
|
|
|
@@ -103967,9 +104032,9 @@ const mdxishCalloutToJsx = () => tree => {
|
|
|
103967
104032
|
visit(tree, NodeTypes.callout, (node, index, parent) => {
|
|
103968
104033
|
if (!parent || index === undefined)
|
|
103969
104034
|
return;
|
|
103970
|
-
|
|
103971
|
-
|
|
103972
|
-
|
|
104035
|
+
// No default-icon fill: an empty `icon` means the author removed it
|
|
104036
|
+
const { icon } = node.data.hProperties;
|
|
104037
|
+
let { theme } = node.data.hProperties;
|
|
103973
104038
|
if (!theme && icon)
|
|
103974
104039
|
theme = themes[icon] || 'default';
|
|
103975
104040
|
// Mutate in place to keep the children array identity so nested callouts in
|
|
@@ -104520,18 +104585,6 @@ const getInlineMdProcessor = ({ safeMode = false } = {}) => {
|
|
|
104520
104585
|
}
|
|
104521
104586
|
return processor;
|
|
104522
104587
|
};
|
|
104523
|
-
/**
|
|
104524
|
-
* Mark re-parsed subtree roots with the string their positions index into, so consumers
|
|
104525
|
-
* slicing by offset use the right source (see `Data.reparseSource`). Only roots are
|
|
104526
|
-
* stamped; descendants resolve via their nearest stamped ancestor. Roots a deeper
|
|
104527
|
-
* re-parse already stamped keep their own string.
|
|
104528
|
-
*/
|
|
104529
|
-
const stampReparseSource = (roots, reparseSource) => {
|
|
104530
|
-
roots.forEach(root => {
|
|
104531
|
-
if (!root.data?.reparseSource)
|
|
104532
|
-
root.data = { ...root.data, reparseSource };
|
|
104533
|
-
});
|
|
104534
|
-
};
|
|
104535
104588
|
/**
|
|
104536
104589
|
* True when a tag name starts with an uppercase letter — ReadMe's marker for
|
|
104537
104590
|
* a custom MDX component (vs a lowercase HTML tag).
|
|
@@ -104618,6 +104671,7 @@ function findBalancedClosingTagIndex(content, tag) {
|
|
|
104618
104671
|
|
|
104619
104672
|
|
|
104620
104673
|
|
|
104674
|
+
|
|
104621
104675
|
/**
|
|
104622
104676
|
* Parse the body of an inline component as phrasing content. Remark always
|
|
104623
104677
|
* wraps bare text in a paragraph; flatten that single-paragraph wrapper so
|
|
@@ -104869,6 +104923,7 @@ function terminateHtmlFlowBlocks(content) {
|
|
|
104869
104923
|
|
|
104870
104924
|
|
|
104871
104925
|
|
|
104926
|
+
|
|
104872
104927
|
// Matches a JSX attribute expression (e.g. `key={i}`) anywhere in a string. One name
|
|
104873
104928
|
// char suffices for existence — `[\w-]+` backtracked quadratically over huge attributes.
|
|
104874
104929
|
const NESTED_ATTR_EXPRESSION_RE = /[\w-]\s*=\s*\{/;
|
|
@@ -104950,26 +105005,12 @@ const parseSibling = (parent, index, sibling, safeMode, promoted) => {
|
|
|
104950
105005
|
}
|
|
104951
105006
|
};
|
|
104952
105007
|
// Ends the position at `consumedLength` so the component doesn't claim trailing
|
|
104953
|
-
// content the tokenizer swallowed into the same html node.
|
|
104954
|
-
// when available: each value line is its source line minus the container prefix
|
|
104955
|
-
// (list indent, `> `) micromark stripped, so those prefixes are counted back in.
|
|
105008
|
+
// content the tokenizer swallowed into the same html node.
|
|
104956
105009
|
const positionEndingAtConsumed = (nodePosition, value, consumedLength, source) => {
|
|
104957
|
-
|
|
105010
|
+
const toSourcePoint = createValueToSourceMapper(nodePosition, value, source);
|
|
105011
|
+
if (!nodePosition || !toSourcePoint)
|
|
104958
105012
|
return nodePosition;
|
|
104959
|
-
|
|
104960
|
-
const sourceLines = source?.slice(nodePosition.start.offset, nodePosition.end?.offset).split('\n');
|
|
104961
|
-
const valueLines = value.split('\n');
|
|
104962
|
-
if (!sourceLines || sourceLines.length !== valueLines.length) {
|
|
104963
|
-
return { start: nodePosition.start, end: pointAfter(nodePosition.start, consumedValue) };
|
|
104964
|
-
}
|
|
104965
|
-
const consumedLines = consumedValue.split('\n');
|
|
104966
|
-
const lastLineIndex = consumedLines.length - 1;
|
|
104967
|
-
const prefixWidth = sourceLines[lastLineIndex].length - valueLines[lastLineIndex].length;
|
|
104968
|
-
const consumedSource = [
|
|
104969
|
-
...sourceLines.slice(0, lastLineIndex),
|
|
104970
|
-
sourceLines[lastLineIndex].slice(0, prefixWidth + consumedLines[lastLineIndex].length),
|
|
104971
|
-
].join('\n');
|
|
104972
|
-
return { start: nodePosition.start, end: pointAfter(nodePosition.start, consumedSource) };
|
|
105013
|
+
return { start: nodePosition.start, end: toSourcePoint(consumedLength) };
|
|
104973
105014
|
};
|
|
104974
105015
|
const createComponentNode = ({ tag, attributes, children, startPosition, endPosition, }) => ({
|
|
104975
105016
|
type: 'mdxJsxFlowElement',
|
|
@@ -104981,14 +105022,6 @@ const createComponentNode = ({ tag, attributes, children, startPosition, endPosi
|
|
|
104981
105022
|
end: endPosition?.end ?? startPosition?.end,
|
|
104982
105023
|
},
|
|
104983
105024
|
});
|
|
104984
|
-
// The promoted node takes over the html node's position, so it also takes over the
|
|
104985
|
-
// coordinate space that position belongs to.
|
|
104986
|
-
const substituteNodeWithMdxNode = (parent, index, mdxNode) => {
|
|
104987
|
-
const replacedSource = parent.children[index]?.data?.reparseSource;
|
|
104988
|
-
if (replacedSource)
|
|
104989
|
-
stampReparseSource([mdxNode], replacedSource);
|
|
104990
|
-
parent.children.splice(index, 1, mdxNode);
|
|
104991
|
-
};
|
|
104992
105025
|
/**
|
|
104993
105026
|
* Transform PascalCase HTML nodes into mdxJsxFlowElement nodes.
|
|
104994
105027
|
*
|
|
@@ -105087,7 +105120,7 @@ function promoteComponentBlocks(tree, safeMode, source) {
|
|
|
105087
105120
|
? positionEndingAtConsumed(node.position, value, leadingWhitespace + openingTagEnd, source)
|
|
105088
105121
|
: node.position,
|
|
105089
105122
|
});
|
|
105090
|
-
|
|
105123
|
+
replaceInheritingReparseSource(parent, index, [componentNode]);
|
|
105091
105124
|
if (remainingContent) {
|
|
105092
105125
|
parseSibling(parent, index, remainingContent, safeMode, promoted);
|
|
105093
105126
|
}
|
|
@@ -105138,7 +105171,7 @@ function promoteComponentBlocks(tree, safeMode, source) {
|
|
|
105138
105171
|
startPosition: node.position,
|
|
105139
105172
|
endPosition,
|
|
105140
105173
|
});
|
|
105141
|
-
|
|
105174
|
+
replaceInheritingReparseSource(parent, index, [componentNode]);
|
|
105142
105175
|
// The unwrap reparented the children out of their paragraph, so re-walk them
|
|
105143
105176
|
// since the children HTML may contain promotable syntax (e.g. `{…}`-attr tags)
|
|
105144
105177
|
if (unwrappedSoleParagraph) {
|
|
@@ -106221,7 +106254,7 @@ const parseApiHeaderTitle = (text) => {
|
|
|
106221
106254
|
* Transform a magicBlock node into final MDAST nodes.
|
|
106222
106255
|
*/
|
|
106223
106256
|
function transformMagicBlock(blockType, data, rawValue, options = {}) {
|
|
106224
|
-
const { compatibilityMode = false, hardBreaks = true } = options;
|
|
106257
|
+
const { compatibilityMode = false, hardBreaks = true, safeMode = false } = options;
|
|
106225
106258
|
// Handle empty data by returning placeholder nodes for known block types
|
|
106226
106259
|
// This allows the editor to show appropriate placeholder UI instead of nothing
|
|
106227
106260
|
if (Object.keys(data).length < 1) {
|
|
@@ -106439,7 +106472,7 @@ function transformMagicBlock(blockType, data, rawValue, options = {}) {
|
|
|
106439
106472
|
wrapPinnedBlocks({
|
|
106440
106473
|
data: {
|
|
106441
106474
|
hName: 'html-block',
|
|
106442
|
-
hProperties: { html: htmlJson.html, runScripts: compatibilityMode },
|
|
106475
|
+
hProperties: { html: htmlJson.html, runScripts: compatibilityMode, safeMode },
|
|
106443
106476
|
},
|
|
106444
106477
|
type: 'html-block',
|
|
106445
106478
|
}, data),
|
|
@@ -106580,6 +106613,7 @@ const magicBlockTransformer = (options = {}) => tree => {
|
|
|
106580
106613
|
|
|
106581
106614
|
|
|
106582
106615
|
|
|
106616
|
+
|
|
106583
106617
|
// `<HTMLBlock …>{`…`}</HTMLBlock>` embedded inside a raw HTML block (e.g. a
|
|
106584
106618
|
// single-line `<div>…</div>`). CommonMark slurps the whole div as one `html`
|
|
106585
106619
|
// node, so the tokenizer never sees the HTMLBlock — we recover it here.
|
|
@@ -106686,7 +106720,8 @@ const mdxishHtmlBlocks = () => tree => {
|
|
|
106686
106720
|
return;
|
|
106687
106721
|
const exprChild = element.children.find(child => child.type === 'mdxFlowExpression' || child.type === 'mdxTextExpression');
|
|
106688
106722
|
const openingTagIndent = (element.position?.start.column ?? 1) - 1;
|
|
106689
|
-
|
|
106723
|
+
const htmlBlock = createHtmlBlockNode(formatHtmlForMdxish(extractTemplateLiteral(exprChild?.value), openingTagIndent), element.position, toRunScripts(jsxAttr(element, 'runScripts')), jsxAttr(element, 'safeMode'));
|
|
106724
|
+
replaceInheritingReparseSource(parent, index, [htmlBlock]);
|
|
106690
106725
|
});
|
|
106691
106726
|
// Shape 2: raw HTML blob.
|
|
106692
106727
|
visit(tree, 'html', (node, index, parent) => {
|
|
@@ -106694,7 +106729,7 @@ const mdxishHtmlBlocks = () => tree => {
|
|
|
106694
106729
|
return;
|
|
106695
106730
|
const replacement = splitRawHtmlBlocks(node);
|
|
106696
106731
|
if (replacement)
|
|
106697
|
-
parent
|
|
106732
|
+
replaceInheritingReparseSource(parent, index, replacement);
|
|
106698
106733
|
});
|
|
106699
106734
|
};
|
|
106700
106735
|
/* harmony default export */ const mdxish_html_blocks = (mdxishHtmlBlocks);
|
|
@@ -106781,6 +106816,7 @@ const hasOnlyWidthAttributes = (cell) => {
|
|
|
106781
106816
|
|
|
106782
106817
|
|
|
106783
106818
|
|
|
106819
|
+
|
|
106784
106820
|
function toImageAlign(value) {
|
|
106785
106821
|
if (value === 'left' || value === 'center' || value === 'right') {
|
|
106786
106822
|
return value;
|
|
@@ -106996,6 +107032,15 @@ const transformAnchor = (jsx) => {
|
|
|
106996
107032
|
position: jsx.position,
|
|
106997
107033
|
};
|
|
106998
107034
|
};
|
|
107035
|
+
/**
|
|
107036
|
+
* Parses an image caption's markdown. The caption is re-parsed on its own, so the
|
|
107037
|
+
* children's positions index into it rather than the document.
|
|
107038
|
+
*/
|
|
107039
|
+
const parseCaptionChildren = (caption) => {
|
|
107040
|
+
const { children } = lib_mdast(caption);
|
|
107041
|
+
stampReparseSource(children, caption);
|
|
107042
|
+
return children;
|
|
107043
|
+
};
|
|
106999
107044
|
/**
|
|
107000
107045
|
* Transforms an `<Image />` JSX element into an image-block MDAST node.
|
|
107001
107046
|
* Normalizes attributes (align, border, width→sizing) and parses caption markdown into children.
|
|
@@ -107026,7 +107071,7 @@ const transformImage = (jsx) => {
|
|
|
107026
107071
|
alt,
|
|
107027
107072
|
border: toBool(border),
|
|
107028
107073
|
caption,
|
|
107029
|
-
children: caption ?
|
|
107074
|
+
children: caption ? parseCaptionChildren(caption) : [],
|
|
107030
107075
|
className,
|
|
107031
107076
|
framed: toBool(framed),
|
|
107032
107077
|
height: height !== undefined ? String(height) : undefined,
|
|
@@ -107363,8 +107408,7 @@ const mdxishJsxToMdast = () => tree => {
|
|
|
107363
107408
|
const newNode = transformer(node);
|
|
107364
107409
|
if (!newNode)
|
|
107365
107410
|
return;
|
|
107366
|
-
|
|
107367
|
-
parent.children[index] = newNode;
|
|
107411
|
+
replaceInheritingReparseSource(parent, index, [newNode]);
|
|
107368
107412
|
});
|
|
107369
107413
|
// Inline JSX components (Anchor)
|
|
107370
107414
|
visit(tree, 'mdxJsxTextElement', (node, index, parent) => {
|
|
@@ -108274,7 +108318,6 @@ function loadComponents() {
|
|
|
108274
108318
|
|
|
108275
108319
|
|
|
108276
108320
|
|
|
108277
|
-
|
|
108278
108321
|
|
|
108279
108322
|
|
|
108280
108323
|
const defaultTransformers = [
|
|
@@ -108430,8 +108473,7 @@ function mdxish(mdContent, opts = {}) {
|
|
|
108430
108473
|
.use(rehypeMdxishComponents, {
|
|
108431
108474
|
components,
|
|
108432
108475
|
processMarkdown: (markdown) => mdxish(markdown, opts),
|
|
108433
|
-
})
|
|
108434
|
-
.use(safeMode ? enforceSafeModeHtmlBlocks : undefined); // Force safeMode on every HTMLBlock; runs last so every producer is covered
|
|
108476
|
+
});
|
|
108435
108477
|
const vfile = new VFile({ value: parserReadyContent });
|
|
108436
108478
|
const mdast = processor.parse(parserReadyContent);
|
|
108437
108479
|
const hast = processor.runSync(mdast, vfile);
|
|
@@ -109403,7 +109445,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"*":["about","acceptCharset","accessK
|
|
|
109403
109445
|
/******/ // startup
|
|
109404
109446
|
/******/ // Load entry module and return exports
|
|
109405
109447
|
/******/ // This entry module used 'module' so it can't be inlined
|
|
109406
|
-
/******/ let __webpack_exports__ = __webpack_require__(
|
|
109448
|
+
/******/ let __webpack_exports__ = __webpack_require__(8846);
|
|
109407
109449
|
/******/
|
|
109408
109450
|
/******/ return __webpack_exports__;
|
|
109409
109451
|
/******/ })()
|