@readme/markdown 9.1.0 → 9.1.2

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.
@@ -1,5 +1,5 @@
1
- import type { RMDXModuleProps, RunOpts } from '../lib/run';
1
+ import type { RunOpts } from '../lib/run';
2
2
  import React from 'react';
3
- type Props = Pick<RMDXModuleProps, 'theme'> & Pick<RunOpts, 'baseUrl' | 'terms' | 'variables'> & React.PropsWithChildren;
3
+ type Props = Pick<RunOpts, 'baseUrl' | 'terms' | 'theme' | 'variables'> & React.PropsWithChildren;
4
4
  declare const Contexts: ({ children, terms, variables, baseUrl, theme }: Props) => React.ReactNode;
5
5
  export default Contexts;
@@ -4,6 +4,7 @@ import remarkFrontmatter from 'remark-frontmatter';
4
4
  import remarkGfm from 'remark-gfm';
5
5
  export interface MdastOpts {
6
6
  components?: Record<string, string>;
7
+ missingComponents?: 'ignore' | 'throw';
7
8
  remarkPlugins?: PluggableList;
8
9
  }
9
10
  export declare const remarkPlugins: ((() => (tree: import("mdast").Root) => void) | (({ copyButtons }?: {
@@ -2,7 +2,8 @@ import type { CompileOptions } from '@mdx-js/mdx';
2
2
  export type CompileOpts = CompileOptions & {
3
3
  components?: Record<string, string>;
4
4
  copyButtons?: boolean;
5
+ missingComponents?: 'ignore' | 'throw';
5
6
  useTailwind?: boolean;
6
7
  };
7
- declare const compile: (text: string, { components, copyButtons, useTailwind, ...opts }?: CompileOpts) => Promise<string>;
8
+ declare const compile: (text: string, { components, missingComponents, copyButtons, useTailwind, ...opts }?: CompileOpts) => Promise<string>;
8
9
  export default compile;
package/dist/lib/run.d.ts CHANGED
@@ -2,16 +2,13 @@ import type { GlossaryTerm } from '../contexts/GlossaryTerms';
2
2
  import type { CustomComponents, RMDXModule } from '../types';
3
3
  import type { Variables } from '../utils/user';
4
4
  import type { RunOptions } from '@mdx-js/mdx';
5
- import type { MDXProps } from 'mdx/types';
6
5
  export type RunOpts = Omit<RunOptions, 'Fragment'> & {
7
6
  baseUrl?: string;
8
7
  components?: CustomComponents;
9
8
  imports?: Record<string, unknown>;
10
9
  terms?: GlossaryTerm[];
10
+ theme?: 'dark' | 'light';
11
11
  variables?: Variables;
12
12
  };
13
- export type RMDXModuleProps = MDXProps & {
14
- theme: 'dark' | 'light';
15
- };
16
13
  declare const run: (string: string, _opts?: RunOpts) => Promise<RMDXModule>;
17
14
  export default run;
@@ -0,0 +1,3 @@
1
+ import type { UseMdxComponents } from '@mdx-js/mdx';
2
+ declare const makeUseMDXComponents: (more?: ReturnType<UseMdxComponents>) => UseMdxComponents;
3
+ export default makeUseMDXComponents;
package/dist/main.js CHANGED
@@ -70614,6 +70614,28 @@ const getExports = (tree) => {
70614
70614
  return Array.from(set);
70615
70615
  };
70616
70616
 
70617
+ ;// ./processor/transform/handle-missing-components.ts
70618
+
70619
+
70620
+
70621
+ const handleMissingComponents = ({ components, missingComponents }) => tree => {
70622
+ const allComponents = new Set([
70623
+ ...getExports(tree),
70624
+ ...Object.keys(components_namespaceObject),
70625
+ ...Object.keys(components),
70626
+ 'Variable',
70627
+ ]);
70628
+ visit(tree, isMDXElement, (node, index, parent) => {
70629
+ if (allComponents.has(node.name) || node.name.match(/^[a-z]/))
70630
+ return;
70631
+ if (missingComponents === 'throw') {
70632
+ throw new Error(`Expected component \`${node.name}\` to be defined: you likely forgot to import, pass, or provide it.`);
70633
+ }
70634
+ parent.children.splice(index, 1);
70635
+ }, true);
70636
+ };
70637
+ /* harmony default export */ const handle_missing_components = (handleMissingComponents);
70638
+
70617
70639
  ;// ./processor/transform/images.ts
70618
70640
 
70619
70641
 
@@ -71017,7 +71039,6 @@ const readmeToMdx = () => tree => {
71017
71039
  },
71018
71040
  },
71019
71041
  };
71020
- // @ts-expect-error -- I have no idea why our mdast types don't always work
71021
71042
  parent.children.splice(index, 1, mdxFlowExpression);
71022
71043
  });
71023
71044
  return tree;
@@ -71236,6 +71257,7 @@ const variables = ({ asMdx } = { asMdx: true }) => tree => {
71236
71257
 
71237
71258
 
71238
71259
 
71260
+
71239
71261
  const defaultTransforms = {
71240
71262
  calloutTransformer: callouts,
71241
71263
  codeTabsTransformer: code_tabs,
@@ -71254,12 +71276,22 @@ const defaultTransforms = {
71254
71276
 
71255
71277
  const remarkPlugins = [remarkFrontmatter, remarkGfm, ...transform];
71256
71278
  const rehypePlugins = [rehypeSlug, transform_mermaid];
71257
- const astProcessor = (opts = { components: {} }) => remark()
71258
- .use(remarkMdx)
71259
- .use(remarkPlugins)
71260
- .use(opts.remarkPlugins)
71261
- .use(transform_variables, { asMdx: false })
71262
- .use(readme_components({ components: opts.components }));
71279
+ const astProcessor = (opts = {}) => {
71280
+ const components = opts.components || {};
71281
+ let processor = remark()
71282
+ .use(remarkMdx)
71283
+ .use(remarkPlugins)
71284
+ .use(opts.remarkPlugins)
71285
+ .use(transform_variables, { asMdx: false })
71286
+ .use(readme_components({ components }));
71287
+ if (['ignore', 'throw'].includes(opts.missingComponents)) {
71288
+ processor = processor.use(handle_missing_components, {
71289
+ components,
71290
+ missingComponents: opts.missingComponents,
71291
+ });
71292
+ }
71293
+ return processor;
71294
+ };
71263
71295
  /* harmony default export */ const ast_processor = (astProcessor);
71264
71296
 
71265
71297
  ;// ./node_modules/markdown-extensions/index.js
@@ -83810,12 +83842,16 @@ const tocHastToMdx = (toc, components) => {
83810
83842
 
83811
83843
 
83812
83844
  const { codeTabsTransformer: compile_codeTabsTransformer, ...transforms } = defaultTransforms;
83813
- const compile_compile = async (text, { components = {}, copyButtons, useTailwind, ...opts } = {}) => {
83845
+ const compile_compile = async (text, { components = {}, missingComponents, copyButtons, useTailwind, ...opts } = {}) => {
83814
83846
  const remarkPlugins = [
83815
83847
  remarkFrontmatter,
83816
83848
  remarkGfm,
83817
83849
  ...Object.values(transforms),
83818
83850
  [compile_codeTabsTransformer, { copyButtons }],
83851
+ [
83852
+ handle_missing_components,
83853
+ { components, missingComponents: ['ignore', 'throw'].includes(missingComponents) ? missingComponents : 'ignore' },
83854
+ ],
83819
83855
  ];
83820
83856
  if (useTailwind) {
83821
83857
  remarkPlugins.push([transform_tailwind, { components }]);
@@ -99168,12 +99204,12 @@ function runSync(code, options) {
99168
99204
  return new Function(String(code))(options)
99169
99205
  }
99170
99206
 
99171
- // EXTERNAL MODULE: external "@readme/variable"
99172
- var variable_ = __webpack_require__(8167);
99173
- var variable_default = /*#__PURE__*/__webpack_require__.n(variable_);
99174
99207
  // EXTERNAL MODULE: ./node_modules/react/jsx-runtime.js
99175
99208
  var jsx_runtime = __webpack_require__(4848);
99176
99209
  var jsx_runtime_namespaceObject = /*#__PURE__*/__webpack_require__.t(jsx_runtime, 2);
99210
+ // EXTERNAL MODULE: external "@readme/variable"
99211
+ var variable_ = __webpack_require__(8167);
99212
+ var variable_default = /*#__PURE__*/__webpack_require__.n(variable_);
99177
99213
  ;// ./contexts/index.tsx
99178
99214
 
99179
99215
 
@@ -99208,14 +99244,7 @@ const User = (variables) => {
99208
99244
  };
99209
99245
  /* harmony default export */ const user = (User);
99210
99246
 
99211
- ;// ./lib/run.tsx
99212
-
99213
-
99214
-
99215
-
99216
-
99217
-
99218
-
99247
+ ;// ./lib/utils/makeUseMdxComponents.ts
99219
99248
 
99220
99249
 
99221
99250
  const makeUseMDXComponents = (more = {}) => {
@@ -99238,12 +99267,23 @@ const makeUseMDXComponents = (more = {}) => {
99238
99267
  ...headings,
99239
99268
  ...more,
99240
99269
  };
99241
- // @ts-expect-error I'm not sure how to coerce the correct type
99242
- return () => components;
99270
+ return (() => components);
99243
99271
  };
99272
+ /* harmony default export */ const makeUseMdxComponents = (makeUseMDXComponents);
99273
+
99274
+ ;// ./lib/run.tsx
99275
+
99276
+
99277
+
99278
+
99279
+
99280
+
99281
+
99282
+
99283
+
99244
99284
  const run_run = async (string, _opts = {}) => {
99245
99285
  const { Fragment } = jsx_runtime_namespaceObject;
99246
- const { components = {}, terms, variables, baseUrl, imports = {}, ...opts } = _opts;
99286
+ const { components = {}, terms, variables, baseUrl, imports = {}, theme, ...opts } = _opts;
99247
99287
  const tocsByTag = {};
99248
99288
  const exportedComponents = Object.entries(components).reduce((memo, [tag, mod]) => {
99249
99289
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -99257,7 +99297,7 @@ const run_run = async (string, _opts = {}) => {
99257
99297
  }
99258
99298
  return memo;
99259
99299
  }, {});
99260
- const exec = (text, { useMDXComponents = makeUseMDXComponents(exportedComponents) } = {}) => {
99300
+ const exec = (text, { useMDXComponents = makeUseMdxComponents(exportedComponents) } = {}) => {
99261
99301
  return run(text, {
99262
99302
  ...jsx_runtime_namespaceObject,
99263
99303
  Fragment,
@@ -99277,7 +99317,7 @@ const run_run = async (string, _opts = {}) => {
99277
99317
  Toc = tocModule.default;
99278
99318
  }
99279
99319
  return {
99280
- default: (props) => (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(contexts, { baseUrl: baseUrl, terms: terms, theme: props.theme, variables: variables },
99320
+ default: (props) => (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(contexts, { baseUrl: baseUrl, terms: terms, theme: theme, variables: variables },
99281
99321
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(Content, { ...props }))),
99282
99322
  toc,
99283
99323
  Toc: props => Toc ? (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(components_TableOfContents, null,
package/dist/main.node.js CHANGED
@@ -75206,6 +75206,28 @@ const getExports = (tree) => {
75206
75206
  return Array.from(set);
75207
75207
  };
75208
75208
 
75209
+ ;// ./processor/transform/handle-missing-components.ts
75210
+
75211
+
75212
+
75213
+ const handleMissingComponents = ({ components, missingComponents }) => tree => {
75214
+ const allComponents = new Set([
75215
+ ...getExports(tree),
75216
+ ...Object.keys(components_namespaceObject),
75217
+ ...Object.keys(components),
75218
+ 'Variable',
75219
+ ]);
75220
+ visit(tree, isMDXElement, (node, index, parent) => {
75221
+ if (allComponents.has(node.name) || node.name.match(/^[a-z]/))
75222
+ return;
75223
+ if (missingComponents === 'throw') {
75224
+ throw new Error(`Expected component \`${node.name}\` to be defined: you likely forgot to import, pass, or provide it.`);
75225
+ }
75226
+ parent.children.splice(index, 1);
75227
+ }, true);
75228
+ };
75229
+ /* harmony default export */ const handle_missing_components = (handleMissingComponents);
75230
+
75209
75231
  ;// ./processor/transform/images.ts
75210
75232
 
75211
75233
 
@@ -75609,7 +75631,6 @@ const readmeToMdx = () => tree => {
75609
75631
  },
75610
75632
  },
75611
75633
  };
75612
- // @ts-expect-error -- I have no idea why our mdast types don't always work
75613
75634
  parent.children.splice(index, 1, mdxFlowExpression);
75614
75635
  });
75615
75636
  return tree;
@@ -75828,6 +75849,7 @@ const variables = ({ asMdx } = { asMdx: true }) => tree => {
75828
75849
 
75829
75850
 
75830
75851
 
75852
+
75831
75853
  const defaultTransforms = {
75832
75854
  calloutTransformer: callouts,
75833
75855
  codeTabsTransformer: code_tabs,
@@ -75846,12 +75868,22 @@ const defaultTransforms = {
75846
75868
 
75847
75869
  const remarkPlugins = [remarkFrontmatter, remarkGfm, ...transform];
75848
75870
  const rehypePlugins = [rehypeSlug, transform_mermaid];
75849
- const astProcessor = (opts = { components: {} }) => remark()
75850
- .use(remarkMdx)
75851
- .use(remarkPlugins)
75852
- .use(opts.remarkPlugins)
75853
- .use(transform_variables, { asMdx: false })
75854
- .use(readme_components({ components: opts.components }));
75871
+ const astProcessor = (opts = {}) => {
75872
+ const components = opts.components || {};
75873
+ let processor = remark()
75874
+ .use(remarkMdx)
75875
+ .use(remarkPlugins)
75876
+ .use(opts.remarkPlugins)
75877
+ .use(transform_variables, { asMdx: false })
75878
+ .use(readme_components({ components }));
75879
+ if (['ignore', 'throw'].includes(opts.missingComponents)) {
75880
+ processor = processor.use(handle_missing_components, {
75881
+ components,
75882
+ missingComponents: opts.missingComponents,
75883
+ });
75884
+ }
75885
+ return processor;
75886
+ };
75855
75887
  /* harmony default export */ const ast_processor = (astProcessor);
75856
75888
 
75857
75889
  ;// ./node_modules/markdown-extensions/index.js
@@ -88402,12 +88434,16 @@ const tocHastToMdx = (toc, components) => {
88402
88434
 
88403
88435
 
88404
88436
  const { codeTabsTransformer: compile_codeTabsTransformer, ...transforms } = defaultTransforms;
88405
- const compile_compile = async (text, { components = {}, copyButtons, useTailwind, ...opts } = {}) => {
88437
+ const compile_compile = async (text, { components = {}, missingComponents, copyButtons, useTailwind, ...opts } = {}) => {
88406
88438
  const remarkPlugins = [
88407
88439
  remarkFrontmatter,
88408
88440
  remarkGfm,
88409
88441
  ...Object.values(transforms),
88410
88442
  [compile_codeTabsTransformer, { copyButtons }],
88443
+ [
88444
+ handle_missing_components,
88445
+ { components, missingComponents: ['ignore', 'throw'].includes(missingComponents) ? missingComponents : 'ignore' },
88446
+ ],
88411
88447
  ];
88412
88448
  if (useTailwind) {
88413
88449
  remarkPlugins.push([transform_tailwind, { components }]);
@@ -103760,12 +103796,12 @@ function runSync(code, options) {
103760
103796
  return new Function(String(code))(options)
103761
103797
  }
103762
103798
 
103763
- // EXTERNAL MODULE: ./node_modules/@readme/variable/dist/index.js
103764
- var dist = __webpack_require__(4355);
103765
- var dist_default = /*#__PURE__*/__webpack_require__.n(dist);
103766
103799
  // EXTERNAL MODULE: ./node_modules/react/jsx-runtime.js
103767
103800
  var jsx_runtime = __webpack_require__(4848);
103768
103801
  var jsx_runtime_namespaceObject = /*#__PURE__*/__webpack_require__.t(jsx_runtime, 2);
103802
+ // EXTERNAL MODULE: ./node_modules/@readme/variable/dist/index.js
103803
+ var dist = __webpack_require__(4355);
103804
+ var dist_default = /*#__PURE__*/__webpack_require__.n(dist);
103769
103805
  ;// ./contexts/index.tsx
103770
103806
 
103771
103807
 
@@ -103800,14 +103836,7 @@ const User = (variables) => {
103800
103836
  };
103801
103837
  /* harmony default export */ const user = (User);
103802
103838
 
103803
- ;// ./lib/run.tsx
103804
-
103805
-
103806
-
103807
-
103808
-
103809
-
103810
-
103839
+ ;// ./lib/utils/makeUseMdxComponents.ts
103811
103840
 
103812
103841
 
103813
103842
  const makeUseMDXComponents = (more = {}) => {
@@ -103830,12 +103859,23 @@ const makeUseMDXComponents = (more = {}) => {
103830
103859
  ...headings,
103831
103860
  ...more,
103832
103861
  };
103833
- // @ts-expect-error I'm not sure how to coerce the correct type
103834
- return () => components;
103862
+ return (() => components);
103835
103863
  };
103864
+ /* harmony default export */ const makeUseMdxComponents = (makeUseMDXComponents);
103865
+
103866
+ ;// ./lib/run.tsx
103867
+
103868
+
103869
+
103870
+
103871
+
103872
+
103873
+
103874
+
103875
+
103836
103876
  const run_run = async (string, _opts = {}) => {
103837
103877
  const { Fragment } = jsx_runtime_namespaceObject;
103838
- const { components = {}, terms, variables, baseUrl, imports = {}, ...opts } = _opts;
103878
+ const { components = {}, terms, variables, baseUrl, imports = {}, theme, ...opts } = _opts;
103839
103879
  const tocsByTag = {};
103840
103880
  const exportedComponents = Object.entries(components).reduce((memo, [tag, mod]) => {
103841
103881
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -103849,7 +103889,7 @@ const run_run = async (string, _opts = {}) => {
103849
103889
  }
103850
103890
  return memo;
103851
103891
  }, {});
103852
- const exec = (text, { useMDXComponents = makeUseMDXComponents(exportedComponents) } = {}) => {
103892
+ const exec = (text, { useMDXComponents = makeUseMdxComponents(exportedComponents) } = {}) => {
103853
103893
  return run(text, {
103854
103894
  ...jsx_runtime_namespaceObject,
103855
103895
  Fragment,
@@ -103869,7 +103909,7 @@ const run_run = async (string, _opts = {}) => {
103869
103909
  Toc = tocModule.default;
103870
103910
  }
103871
103911
  return {
103872
- default: (props) => (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(contexts, { baseUrl: baseUrl, terms: terms, theme: props.theme, variables: variables },
103912
+ default: (props) => (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(contexts, { baseUrl: baseUrl, terms: terms, theme: theme, variables: variables },
103873
103913
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(Content, { ...props }))),
103874
103914
  toc,
103875
103915
  Toc: props => Toc ? (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(components_TableOfContents, null,