@readme/markdown 15.9.2 → 15.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/constants.d.ts +2 -0
- package/dist/lib/utils/mdxish/mdxish-variables.d.ts +2 -0
- package/dist/main.js +49 -36
- package/dist/main.node.js +49 -36
- package/dist/main.node.js.map +1 -1
- package/dist/processor/transform/mdxish/resolve-deferred-attribute-expression-props.d.ts +6 -2
- package/dist/render-fixture.node.js +49 -36
- package/dist/render-fixture.node.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,16 +1,20 @@
|
|
|
1
|
+
import type { Variables } from '../../../types';
|
|
1
2
|
import type { Root } from 'hast';
|
|
2
3
|
import type { Plugin } from 'unified';
|
|
4
|
+
interface Options {
|
|
5
|
+
variables?: Variables;
|
|
6
|
+
}
|
|
3
7
|
/**
|
|
4
8
|
* Resolve attribute expressions that `mdxJsxElementHandler` deferred.
|
|
5
9
|
*
|
|
6
10
|
* The handler stashed each attribute expression's source in `node.data.deferredExpressions`
|
|
7
11
|
* (keyed by prop name) instead of evaluating eagerly, because an eager result can be a React
|
|
8
12
|
* element or function that rehypeRaw's `structuredClone` passthrough rejects. Now that we're
|
|
9
|
-
* past the clone, evaluate each source with a scope of `{ React, ...mdxishScope }` and write
|
|
13
|
+
* past the clone, evaluate each source with a scope of `{ user, React, ...mdxishScope }` and write
|
|
10
14
|
* the real value into `properties` (e.g. an array of objects whose fields are React elements).
|
|
11
15
|
*
|
|
12
16
|
* Must run after `rehypeRaw` (past the clone) but before `normalizeMdxJsxNodes` rewrites these
|
|
13
17
|
* `mdx-jsx` nodes into plain elements. Skipped in safeMode, which keeps expressions literal.
|
|
14
18
|
*/
|
|
15
|
-
declare const resolveDeferredAttributeExpressionProps: Plugin<[], Root>;
|
|
19
|
+
declare const resolveDeferredAttributeExpressionProps: Plugin<[Options?], Root>;
|
|
16
20
|
export default resolveDeferredAttributeExpressionProps;
|
|
@@ -19358,6 +19358,8 @@ const TOKENIZER_MDX_COMPONENT_EXCLUDED_TAGS = new Set([
|
|
|
19358
19358
|
* run after rehype (where hast `tagName` is normalized to lowercase).
|
|
19359
19359
|
*/
|
|
19360
19360
|
const INLINE_COMPONENT_TAGS_LOWER = new Set([...INLINE_COMPONENT_TAGS].map(t => t.toLowerCase()));
|
|
19361
|
+
/** Raw markup props injected with `dangerouslySetInnerHTML` by HTMLBlock and Embed; never interpolate reader values. */
|
|
19362
|
+
const RAW_HTML_PROP_NAMES = new Set(['html']);
|
|
19361
19363
|
|
|
19362
19364
|
;// ./node_modules/github-slugger/regex.js
|
|
19363
19365
|
// This module is generated by `script/`.
|
|
@@ -127792,33 +127794,75 @@ function repairMistakenTableClosers(content) {
|
|
|
127792
127794
|
return applyInserts(content, edits).value;
|
|
127793
127795
|
}
|
|
127794
127796
|
|
|
127797
|
+
;// ./lib/utils/mdxish/mdxish-variables.ts
|
|
127798
|
+
|
|
127799
|
+
|
|
127800
|
+
// The `$` guard skips template-literal interpolation: `${user.name}` embeds `{user.name}`, and
|
|
127801
|
+
// substituting it would leave a mangled `` `Hi $Name` `` behind. Those belong to an expression,
|
|
127802
|
+
// which either evaluated already or is meant to stay literal.
|
|
127803
|
+
const MDX_VARIABLE_REGEX = new RegExp(`(?<!\\$)${variable_dist.MDX_VARIABLE_REGEXP}`, 'gu');
|
|
127804
|
+
// A whole attribute expression that is one `user.*` reference, e.g. the `user.name` in `title={user.name}`.
|
|
127805
|
+
const BARE_VARIABLE_REGEX = new RegExp(`^${variable_dist.MDX_VARIABLE_REGEXP}$`, 'u');
|
|
127806
|
+
// Bracket notation names the same variable as dot notation, so normalize it before substituting.
|
|
127807
|
+
// Escaped and `$`-prefixed forms are left alone so a reference that stays literal keeps its source.
|
|
127808
|
+
// A closing escape needs no lookahead: requiring a literal `]}` already rules out `]\}`.
|
|
127809
|
+
const BRACKET_NOTATION_REGEX = /(?<![$\\])\{user\[['"](\w+)['"]\]\}/gu;
|
|
127810
|
+
/**
|
|
127811
|
+
* Resolve `{user.*}` in a JSX attribute value against the same `user` binding the rmdx engine gets,
|
|
127812
|
+
* so both engines agree. Body text differs on empty values: `Variable` falls back to the default.
|
|
127813
|
+
*
|
|
127814
|
+
* Legacy `<<...>>` is valid inside a quoted attribute but deliberately left literal — attributes are
|
|
127815
|
+
* an MDX surface, and `{user.*}` is the syntax authors use there.
|
|
127816
|
+
*/
|
|
127817
|
+
function resolveAttributeVariables(value, user) {
|
|
127818
|
+
if (!value.includes('{user'))
|
|
127819
|
+
return value;
|
|
127820
|
+
return value
|
|
127821
|
+
.replace(BRACKET_NOTATION_REGEX, '{user.$1}')
|
|
127822
|
+
.replace(MDX_VARIABLE_REGEX, (source, escapePrefix, name, escapeSuffix) => {
|
|
127823
|
+
if (escapePrefix || escapeSuffix)
|
|
127824
|
+
return source;
|
|
127825
|
+
return stringifyVariableValue(user[name]);
|
|
127826
|
+
});
|
|
127827
|
+
}
|
|
127828
|
+
/** Whether an attribute expression's source is a bare `user.*` reference, left for render-time substitution. */
|
|
127829
|
+
const isBareVariableReference = (source) => BARE_VARIABLE_REGEX.test(`{${source.trim()}}`.replace(BRACKET_NOTATION_REGEX, '{user.$1}'));
|
|
127830
|
+
|
|
127795
127831
|
;// ./processor/transform/mdxish/resolve-deferred-attribute-expression-props.ts
|
|
127796
127832
|
|
|
127797
127833
|
|
|
127798
127834
|
|
|
127799
127835
|
|
|
127836
|
+
|
|
127837
|
+
|
|
127838
|
+
|
|
127800
127839
|
/**
|
|
127801
127840
|
* Resolve attribute expressions that `mdxJsxElementHandler` deferred.
|
|
127802
127841
|
*
|
|
127803
127842
|
* The handler stashed each attribute expression's source in `node.data.deferredExpressions`
|
|
127804
127843
|
* (keyed by prop name) instead of evaluating eagerly, because an eager result can be a React
|
|
127805
127844
|
* element or function that rehypeRaw's `structuredClone` passthrough rejects. Now that we're
|
|
127806
|
-
* past the clone, evaluate each source with a scope of `{ React, ...mdxishScope }` and write
|
|
127845
|
+
* past the clone, evaluate each source with a scope of `{ user, React, ...mdxishScope }` and write
|
|
127807
127846
|
* the real value into `properties` (e.g. an array of objects whose fields are React elements).
|
|
127808
127847
|
*
|
|
127809
127848
|
* Must run after `rehypeRaw` (past the clone) but before `normalizeMdxJsxNodes` rewrites these
|
|
127810
127849
|
* `mdx-jsx` nodes into plain elements. Skipped in safeMode, which keeps expressions literal.
|
|
127811
127850
|
*/
|
|
127812
|
-
const resolveDeferredAttributeExpressionProps = () => (tree, file) => {
|
|
127851
|
+
const resolveDeferredAttributeExpressionProps = ({ variables } = {}) => (tree, file) => {
|
|
127813
127852
|
const scope = { ...file.data.mdxishScope, React: (external_react_default()) };
|
|
127853
|
+
// `user` only when variables were supplied, as in `evaluateExpressions`.
|
|
127854
|
+
const userScope = variables ? { user: user(variables), ...scope } : scope;
|
|
127814
127855
|
visit(tree, 'mdx-jsx', (node) => {
|
|
127815
127856
|
const deferredExpressions = node.data?.deferredExpressions;
|
|
127816
127857
|
if (!deferredExpressions)
|
|
127817
127858
|
return;
|
|
127818
127859
|
const properties = node.properties;
|
|
127819
127860
|
Object.entries(deferredExpressions).forEach(([name, source]) => {
|
|
127861
|
+
// Raw markup never gets `user`: a reader's values reaching `dangerouslySetInnerHTML` is an injection
|
|
127862
|
+
// vector. A bare `{user.x}` keeps render-time substitution, which stringifies structured values.
|
|
127863
|
+
const canReadUser = !RAW_HTML_PROP_NAMES.has(name) && !isBareVariableReference(source);
|
|
127820
127864
|
try {
|
|
127821
|
-
const result = evalExpression(source, scope);
|
|
127865
|
+
const result = evalExpression(source, canReadUser ? userScope : scope);
|
|
127822
127866
|
// hast/HTML `style` is a plain CSS string; a `style={{...}}` expression evaluates to
|
|
127823
127867
|
// a JS object, which must be serialized or it renders as the literal "[object Object]".
|
|
127824
127868
|
properties[name] = name === 'style' && style_object_to_css_isPlainObject(result) ? styleObjectToCssText(result) : result;
|
|
@@ -128428,7 +128472,7 @@ function mdxish(mdContent, opts = {}) {
|
|
|
128428
128472
|
.use(preserveBooleanProperties) // RehypeRaw converts boolean properties to empty strings
|
|
128429
128473
|
.use(rehypeRaw, { passThrough: ['html-block', 'mdx-jsx'] }) // MDX JSX nodes bypass parse5's string-only HTML round-trip
|
|
128430
128474
|
.use(restoreBooleanProperties)
|
|
128431
|
-
.use(safeMode ? undefined : resolve_deferred_attribute_expression_props) // Evaluate deferred attribute expressions on mdx-jsx nodes (now past rehypeRaw's clone)
|
|
128475
|
+
.use(safeMode ? undefined : resolve_deferred_attribute_expression_props, { variables }) // Evaluate deferred attribute expressions on mdx-jsx nodes (now past rehypeRaw's clone)
|
|
128432
128476
|
.use(normalize_mdx_jsx_nodes) // Rewrite `mdx-jsx` back to standard `element` nodes for downstream plugins
|
|
128433
128477
|
.use(sanitize ? rehypeStripTags : undefined) // Strip STRIPPED_TAG_NAMES elements; this pipeline has no sanitization step
|
|
128434
128478
|
.use(rehypeFlattenTableCellParagraphs) // Remove <p> wrappers inside table cells to prevent margin issues
|
|
@@ -128593,36 +128637,6 @@ const makeUseMDXComponents = (more = {}) => {
|
|
|
128593
128637
|
};
|
|
128594
128638
|
/* harmony default export */ const makeUseMdxComponents = (makeUseMDXComponents);
|
|
128595
128639
|
|
|
128596
|
-
;// ./lib/utils/mdxish/mdxish-variables.ts
|
|
128597
|
-
|
|
128598
|
-
|
|
128599
|
-
// The `$` guard skips template-literal interpolation: `${user.name}` embeds `{user.name}`, and
|
|
128600
|
-
// substituting it would leave a mangled `` `Hi $Name` `` behind. Those belong to an expression,
|
|
128601
|
-
// which either evaluated already or is meant to stay literal.
|
|
128602
|
-
const MDX_VARIABLE_REGEX = new RegExp(`(?<!\\$)${variable_dist.MDX_VARIABLE_REGEXP}`, 'gu');
|
|
128603
|
-
// Bracket notation names the same variable as dot notation, so normalize it before substituting.
|
|
128604
|
-
// Escaped and `$`-prefixed forms are left alone so a reference that stays literal keeps its source.
|
|
128605
|
-
// A closing escape needs no lookahead: requiring a literal `]}` already rules out `]\}`.
|
|
128606
|
-
const BRACKET_NOTATION_REGEX = /(?<![$\\])\{user\[['"](\w+)['"]\]\}/gu;
|
|
128607
|
-
/**
|
|
128608
|
-
* Resolve `{user.*}` in a JSX attribute value against the same `user` binding the rmdx engine gets,
|
|
128609
|
-
* so both engines agree. Body text differs on empty values: `Variable` falls back to the default.
|
|
128610
|
-
*
|
|
128611
|
-
* Legacy `<<...>>` is valid inside a quoted attribute but deliberately left literal — attributes are
|
|
128612
|
-
* an MDX surface, and `{user.*}` is the syntax authors use there.
|
|
128613
|
-
*/
|
|
128614
|
-
function resolveAttributeVariables(value, user) {
|
|
128615
|
-
if (!value.includes('{user'))
|
|
128616
|
-
return value;
|
|
128617
|
-
return value
|
|
128618
|
-
.replace(BRACKET_NOTATION_REGEX, '{user.$1}')
|
|
128619
|
-
.replace(MDX_VARIABLE_REGEX, (source, escapePrefix, name, escapeSuffix) => {
|
|
128620
|
-
if (escapePrefix || escapeSuffix)
|
|
128621
|
-
return source;
|
|
128622
|
-
return stringifyVariableValue(user[name]);
|
|
128623
|
-
});
|
|
128624
|
-
}
|
|
128625
|
-
|
|
128626
128640
|
;// ./lib/utils/mdxish/mdxish-render-utils.tsx
|
|
128627
128641
|
|
|
128628
128642
|
|
|
@@ -128633,6 +128647,7 @@ function resolveAttributeVariables(value, user) {
|
|
|
128633
128647
|
|
|
128634
128648
|
|
|
128635
128649
|
|
|
128650
|
+
|
|
128636
128651
|
/** Flatten CustomComponents into a component map for rehype-react */
|
|
128637
128652
|
function exportComponentsForRehype(components) {
|
|
128638
128653
|
const exported = Object.entries(components).reduce((memo, [tag, mod]) => {
|
|
@@ -128665,8 +128680,6 @@ function exportComponentsForRehype(components) {
|
|
|
128665
128680
|
* deliberately leaves mermaid alone; resolving it again here would override that.
|
|
128666
128681
|
*/
|
|
128667
128682
|
const CODE_TAG_NAMES = new Set(['code']);
|
|
128668
|
-
/** Raw markup injected with `dangerouslySetInnerHTML` by HTMLBlock and Embed — never interpolate. */
|
|
128669
|
-
const RAW_HTML_PROP_NAMES = new Set(['html']);
|
|
128670
128683
|
/**
|
|
128671
128684
|
* Resolve `{user.*}` in string-valued props. Body text is handled by the `Variable` component, but
|
|
128672
128685
|
* attributes are plain strings, so they are substituted here — at render time, so that a
|