@readme/markdown 9.0.6 → 9.1.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/dist/main.node.js CHANGED
@@ -16302,9 +16302,15 @@ const themes = {
16302
16302
  '\u2139\uFE0F': 'info',
16303
16303
  '\u26A0': 'warn',
16304
16304
  };
16305
+ const defaultIcons = {
16306
+ info: '\uD83D\uDCD8',
16307
+ warn: '\uD83D\uDEA7',
16308
+ okay: '\uD83D\uDC4D',
16309
+ error: '\u2757\uFE0F',
16310
+ };
16305
16311
  const Callout = (props) => {
16306
- const { attributes, children, icon, empty } = props;
16307
- const theme = props.theme || themes[icon] || 'default';
16312
+ const { attributes, children, theme, empty } = props;
16313
+ const icon = props.icon || defaultIcons[theme] || '';
16308
16314
  return (
16309
16315
  // @ts-expect-error -- theme is not a valid attribute
16310
16316
  // eslint-disable-next-line react/jsx-props-no-spreading, react/no-unknown-property
@@ -16322,7 +16328,7 @@ const Callout = (props) => {
16322
16328
  const Card = ({ children, href, icon, iconColor, target, title }) => {
16323
16329
  const Tag = href ? 'a' : 'div';
16324
16330
  return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(Tag, { className: "Card", href: href, target: target },
16325
- icon && external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("i", { className: `Card-icon fa-duotone fa-solid ${icon}`, style: { color: `${iconColor}` } }),
16331
+ icon && external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("i", { className: `Card-icon fa-duotone fa-solid ${icon}`, style: { '--Card-icon-color': iconColor } }),
16326
16332
  title && external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("p", { className: "Card-title" }, title),
16327
16333
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("div", { className: "Card-content" }, children)));
16328
16334
  };
@@ -16336,9 +16342,15 @@ const CardsGrid = ({ columns = 2, children }) => {
16336
16342
  // EXTERNAL MODULE: ./node_modules/copy-to-clipboard/index.js
16337
16343
  var copy_to_clipboard = __webpack_require__(7965);
16338
16344
  var copy_to_clipboard_default = /*#__PURE__*/__webpack_require__.n(copy_to_clipboard);
16345
+ ;// ./contexts/Theme.ts
16346
+
16347
+ const ThemeContext = (0,external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createContext)('light');
16348
+ /* harmony default export */ const Theme = (ThemeContext);
16349
+
16339
16350
  ;// ./components/Code/index.tsx
16340
16351
 
16341
16352
 
16353
+
16342
16354
  // Only load CodeMirror in the browser, for SSR
16343
16355
  // apps. Necessary because of people like this:
16344
16356
  // https://github.com/codemirror/CodeMirror/issues/3701#issuecomment-164904534
@@ -16365,7 +16377,8 @@ function CopyCode({ codeRef, rootClass = 'rdmd-code-copy', className = '', }) {
16365
16377
  return external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("button", { ref: buttonRef, "aria-label": "Copy Code", className: `${rootClass} ${className}`, onClick: copier });
16366
16378
  }
16367
16379
  const Code = (props) => {
16368
- const { children, copyButtons, lang, theme, value } = props;
16380
+ const { children, copyButtons, lang, value } = props;
16381
+ const theme = (0,external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.useContext)(Theme);
16369
16382
  const language = canonicalLanguage(lang);
16370
16383
  const codeRef = (0,external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createRef)();
16371
16384
  const codeOpts = {
@@ -16389,9 +16402,11 @@ var index_node = __webpack_require__(3368);
16389
16402
  ;// ./components/CodeTabs/index.tsx
16390
16403
 
16391
16404
 
16405
+
16392
16406
  let mermaid;
16393
16407
  const CodeTabs = (props) => {
16394
- const { children, theme } = props;
16408
+ const { children } = props;
16409
+ const theme = (0,external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.useContext)(Theme);
16395
16410
  // render Mermaid diagram
16396
16411
  (0,external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.useEffect)(() => {
16397
16412
  if (typeof window !== 'undefined') {
@@ -57758,6 +57773,7 @@ var NodeTypes;
57758
57773
 
57759
57774
 
57760
57775
 
57776
+
57761
57777
  const callouts_regex = `^(${emoji_regex().source}|⚠)(\\s+|$)`;
57762
57778
  const calloutTransformer = () => {
57763
57779
  return (tree) => {
@@ -57769,6 +57785,7 @@ const calloutTransformer = () => {
57769
57785
  if (icon && match) {
57770
57786
  const heading = startText.slice(match.length);
57771
57787
  const empty = !heading.length && node.children[0].children.length === 1;
57788
+ const theme = themes[icon] || 'default';
57772
57789
  node.children[0].children[0].value = heading;
57773
57790
  Object.assign(node, {
57774
57791
  type: NodeTypes.callout,
@@ -57777,6 +57794,7 @@ const calloutTransformer = () => {
57777
57794
  hProperties: {
57778
57795
  icon,
57779
57796
  empty,
57797
+ theme,
57780
57798
  },
57781
57799
  },
57782
57800
  });
@@ -75188,6 +75206,28 @@ const getExports = (tree) => {
75188
75206
  return Array.from(set);
75189
75207
  };
75190
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
+
75191
75231
  ;// ./processor/transform/images.ts
75192
75232
 
75193
75233
 
@@ -75298,6 +75338,7 @@ const mermaidTransformer = () => (tree) => {
75298
75338
 
75299
75339
 
75300
75340
 
75341
+
75301
75342
  const readme_components_types = {
75302
75343
  Callout: NodeTypes.callout,
75303
75344
  Code: 'code',
@@ -75414,13 +75455,15 @@ const coerceJsxToMd = ({ components = {}, html = false } = {}) => (node, index,
75414
75455
  return SKIP;
75415
75456
  }
75416
75457
  else if (node.name === 'Callout') {
75458
+ const attrs = getAttrs(node);
75417
75459
  const { icon, empty = false } = getAttrs(node);
75460
+ const theme = attrs.theme || themes[icon] || 'default';
75418
75461
  const mdNode = {
75419
75462
  children: node.children,
75420
75463
  type: NodeTypes.callout,
75421
75464
  data: {
75422
75465
  hName: node.name,
75423
- hProperties: { icon, empty },
75466
+ hProperties: { icon, empty, theme },
75424
75467
  },
75425
75468
  position: node.position,
75426
75469
  };
@@ -75554,6 +75597,42 @@ const readmeToMdx = () => tree => {
75554
75597
  },
75555
75598
  });
75556
75599
  });
75600
+ const isVariable = (node) => 'type' in node && node.type === NodeTypes.variable;
75601
+ visit(tree, isVariable, (node, index, parent) => {
75602
+ const identifier = (node.data.hProperties.variable || node.data.hProperties.name).toString();
75603
+ const validIdentifier = identifier.match(/^(\p{Letter}|[$_])(\p{Letter}|[$_0-9])*$/u);
75604
+ const value = validIdentifier ? `user.${identifier}` : `user[${JSON.stringify(identifier)}]`;
75605
+ const mdxFlowExpression = {
75606
+ type: 'mdxFlowExpression',
75607
+ value,
75608
+ data: {
75609
+ estree: {
75610
+ type: 'Program',
75611
+ body: [
75612
+ {
75613
+ type: 'ExpressionStatement',
75614
+ expression: {
75615
+ type: 'MemberExpression',
75616
+ object: {
75617
+ type: 'Identifier',
75618
+ name: 'user',
75619
+ },
75620
+ property: {
75621
+ type: 'Identifier',
75622
+ name: identifier,
75623
+ },
75624
+ computed: false,
75625
+ optional: false,
75626
+ },
75627
+ },
75628
+ ],
75629
+ sourceType: 'module',
75630
+ comments: [],
75631
+ },
75632
+ },
75633
+ };
75634
+ parent.children.splice(index, 1, mdxFlowExpression);
75635
+ });
75557
75636
  return tree;
75558
75637
  };
75559
75638
  /* harmony default export */ const readme_to_mdx = (readmeToMdx);
@@ -75770,6 +75849,7 @@ const variables = ({ asMdx } = { asMdx: true }) => tree => {
75770
75849
 
75771
75850
 
75772
75851
 
75852
+
75773
75853
  const defaultTransforms = {
75774
75854
  calloutTransformer: callouts,
75775
75855
  codeTabsTransformer: code_tabs,
@@ -75788,12 +75868,22 @@ const defaultTransforms = {
75788
75868
 
75789
75869
  const remarkPlugins = [remarkFrontmatter, remarkGfm, ...transform];
75790
75870
  const rehypePlugins = [rehypeSlug, transform_mermaid];
75791
- const astProcessor = (opts = { components: {} }) => remark()
75792
- .use(remarkMdx)
75793
- .use(remarkPlugins)
75794
- .use(opts.remarkPlugins)
75795
- .use(transform_variables, { asMdx: false })
75796
- .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
+ };
75797
75887
  /* harmony default export */ const ast_processor = (astProcessor);
75798
75888
 
75799
75889
  ;// ./node_modules/markdown-extensions/index.js
@@ -88344,12 +88434,16 @@ const tocHastToMdx = (toc, components) => {
88344
88434
 
88345
88435
 
88346
88436
  const { codeTabsTransformer: compile_codeTabsTransformer, ...transforms } = defaultTransforms;
88347
- const compile_compile = async (text, { components = {}, copyButtons, useTailwind, ...opts } = {}) => {
88437
+ const compile_compile = async (text, { components = {}, missingComponents, copyButtons, useTailwind, ...opts } = {}) => {
88348
88438
  const remarkPlugins = [
88349
88439
  remarkFrontmatter,
88350
88440
  remarkGfm,
88351
88441
  ...Object.values(transforms),
88352
88442
  [compile_codeTabsTransformer, { copyButtons }],
88443
+ [
88444
+ handle_missing_components,
88445
+ { components, missingComponents: ['ignore', 'throw'].includes(missingComponents) ? missingComponents : 'ignore' },
88446
+ ],
88353
88447
  ];
88354
88448
  if (useTailwind) {
88355
88449
  remarkPlugins.push([transform_tailwind, { components }]);
@@ -93225,15 +93319,6 @@ ${reformatHTML(html)}
93225
93319
  };
93226
93320
  /* harmony default export */ const html_block = (htmlBlock);
93227
93321
 
93228
- ;// ./processor/compile/variable.ts
93229
- const variable = (node) => {
93230
- // @note: coming from RDMD, it's set as `variable`. But when mdx is parsed,
93231
- // it's set as `name`
93232
- const name = node.data.hProperties.variable || node.data.hProperties.name;
93233
- return name.toString().match(/ /) ? `{user[${JSON.stringify(name)}]}` : `{user.${name}}`;
93234
- };
93235
- /* harmony default export */ const compile_variable = (variable);
93236
-
93237
93322
  ;// ./processor/compile/index.ts
93238
93323
 
93239
93324
 
@@ -93242,7 +93327,6 @@ const variable = (node) => {
93242
93327
 
93243
93328
 
93244
93329
 
93245
-
93246
93330
  function compilers() {
93247
93331
  const data = this.data();
93248
93332
  const toMarkdownExtensions = data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
@@ -93254,7 +93338,6 @@ function compilers() {
93254
93338
  [NodeTypes.glossary]: compile_compatibility,
93255
93339
  [NodeTypes.htmlBlock]: html_block,
93256
93340
  [NodeTypes.reusableContent]: compile_compatibility,
93257
- [NodeTypes.variable]: compile_variable,
93258
93341
  embed: compile_compatibility,
93259
93342
  escape: compile_compatibility,
93260
93343
  figure: compile_compatibility,
@@ -103713,24 +103796,25 @@ function runSync(code, options) {
103713
103796
  return new Function(String(code))(options)
103714
103797
  }
103715
103798
 
103716
- // EXTERNAL MODULE: ./node_modules/@readme/variable/dist/index.js
103717
- var dist = __webpack_require__(4355);
103718
- var dist_default = /*#__PURE__*/__webpack_require__.n(dist);
103719
103799
  // EXTERNAL MODULE: ./node_modules/react/jsx-runtime.js
103720
103800
  var jsx_runtime = __webpack_require__(4848);
103721
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);
103722
103805
  ;// ./contexts/index.tsx
103723
103806
 
103724
103807
 
103725
103808
 
103726
103809
 
103810
+
103727
103811
  const compose = (children, ...contexts) => {
103728
103812
  return contexts.reduce((content, [Context, value]) => {
103729
103813
  return external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(Context.Provider, { value: value }, content);
103730
103814
  }, children);
103731
103815
  };
103732
- const Contexts = ({ children, terms = [], variables = { user: {}, defaults: [] }, baseUrl = '/' }) => {
103733
- return compose(children, [GlossaryTerms, terms], [dist.VariablesContext, variables], [BaseUrl, baseUrl]);
103816
+ const Contexts = ({ children, terms = [], variables = { user: {}, defaults: [] }, baseUrl = '/', theme }) => {
103817
+ return compose(children, [GlossaryTerms, terms], [dist.VariablesContext, variables], [BaseUrl, baseUrl], [Theme, theme]);
103734
103818
  };
103735
103819
  /* harmony default export */ const contexts = (Contexts);
103736
103820
 
@@ -103752,14 +103836,7 @@ const User = (variables) => {
103752
103836
  };
103753
103837
  /* harmony default export */ const user = (User);
103754
103838
 
103755
- ;// ./lib/run.tsx
103756
-
103757
-
103758
-
103759
-
103760
-
103761
-
103762
-
103839
+ ;// ./lib/utils/makeUseMdxComponents.ts
103763
103840
 
103764
103841
 
103765
103842
  const makeUseMDXComponents = (more = {}) => {
@@ -103782,9 +103859,20 @@ const makeUseMDXComponents = (more = {}) => {
103782
103859
  ...headings,
103783
103860
  ...more,
103784
103861
  };
103785
- // @ts-expect-error I'm not sure how to coerce the correct type
103786
- return () => components;
103862
+ return (() => components);
103787
103863
  };
103864
+ /* harmony default export */ const makeUseMdxComponents = (makeUseMDXComponents);
103865
+
103866
+ ;// ./lib/run.tsx
103867
+
103868
+
103869
+
103870
+
103871
+
103872
+
103873
+
103874
+
103875
+
103788
103876
  const run_run = async (string, _opts = {}) => {
103789
103877
  const { Fragment } = jsx_runtime_namespaceObject;
103790
103878
  const { components = {}, terms, variables, baseUrl, imports = {}, ...opts } = _opts;
@@ -103801,7 +103889,7 @@ const run_run = async (string, _opts = {}) => {
103801
103889
  }
103802
103890
  return memo;
103803
103891
  }, {});
103804
- const exec = (text, { useMDXComponents = makeUseMDXComponents(exportedComponents) } = {}) => {
103892
+ const exec = (text, { useMDXComponents = makeUseMdxComponents(exportedComponents) } = {}) => {
103805
103893
  return run(text, {
103806
103894
  ...jsx_runtime_namespaceObject,
103807
103895
  Fragment,
@@ -103821,7 +103909,7 @@ const run_run = async (string, _opts = {}) => {
103821
103909
  Toc = tocModule.default;
103822
103910
  }
103823
103911
  return {
103824
- default: props => (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(contexts, { baseUrl: baseUrl, terms: terms, variables: variables },
103912
+ 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 },
103825
103913
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(Content, { ...props }))),
103826
103914
  toc,
103827
103915
  Toc: props => Toc ? (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(components_TableOfContents, null,