@readme/markdown 6.75.0-beta.63 → 6.75.0-beta.64

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.
@@ -11,10 +11,10 @@ interface ImageProps {
11
11
  title?: string;
12
12
  width?: string;
13
13
  lazy?: boolean;
14
+ children?: [React.ReactElement];
14
15
  }
15
16
 
16
17
  const Image = (Props: ImageProps) => {
17
- const [lightbox, setLightbox] = React.useState(false);
18
18
  const {
19
19
  align = '',
20
20
  alt = '',
@@ -26,8 +26,11 @@ const Image = (Props: ImageProps) => {
26
26
  title = '',
27
27
  width = 'auto',
28
28
  lazy = false,
29
+ children,
29
30
  } = Props;
30
31
 
32
+ const [lightbox, setLightbox] = React.useState(false);
33
+
31
34
  if (className === 'emoji') {
32
35
  return <img src={src} width={width} height={height} title={title} alt={alt} loading={lazy ? 'lazy' : 'eager'} />;
33
36
  }
@@ -76,7 +79,7 @@ const Image = (Props: ImageProps) => {
76
79
  alt={alt}
77
80
  loading={lazy ? 'lazy' : 'eager'}
78
81
  />
79
- <figcaption>{caption}</figcaption>
82
+ <figcaption>{children || caption}</figcaption>
80
83
  </figure>
81
84
  </span>
82
85
  </span>
@@ -10,6 +10,7 @@ interface ImageProps {
10
10
  title?: string;
11
11
  width?: string;
12
12
  lazy?: boolean;
13
+ children?: [React.ReactElement];
13
14
  }
14
15
  declare const Image: (Props: ImageProps) => React.JSX.Element;
15
16
  export default Image;
package/dist/main.js CHANGED
@@ -14444,8 +14444,8 @@ const CreateHeading = (depth) => (props) => external_amd_react_commonjs_react_co
14444
14444
  ;// CONCATENATED MODULE: ./components/Image/index.tsx
14445
14445
 
14446
14446
  const Image = (Props) => {
14447
+ const { align = '', alt = '', border = false, caption, className = '', height = 'auto', src, title = '', width = 'auto', lazy = false, children, } = Props;
14447
14448
  const [lightbox, setLightbox] = external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.useState(false);
14448
- const { align = '', alt = '', border = false, caption, className = '', height = 'auto', src, title = '', width = 'auto', lazy = false, } = Props;
14449
14449
  if (className === 'emoji') {
14450
14450
  return external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("img", { src: src, width: width, height: height, title: title, alt: alt, loading: lazy ? 'lazy' : 'eager' });
14451
14451
  }
@@ -14476,7 +14476,7 @@ const Image = (Props) => {
14476
14476
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { className: "lightbox-inner" },
14477
14477
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("figure", null,
14478
14478
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("img", { src: src, width: width, height: height, title: title, className: `img img-align-center ${border ? 'border' : ''}`, alt: alt, loading: lazy ? 'lazy' : 'eager' }),
14479
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("figcaption", null, caption)))));
14479
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("figcaption", null, children || caption)))));
14480
14480
  }
14481
14481
  return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("p", null,
14482
14482
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { "aria-label": alt, className: `img lightbox ${lightbox ? 'open' : 'closed'}`, onClick: toggle, onKeyDown: handleKeyDown, role: 'button', tabIndex: 0 },
@@ -48550,31 +48550,159 @@ const embedTransformer = () => {
48550
48550
  };
48551
48551
  /* harmony default export */ const transform_embeds = (embedTransformer);
48552
48552
 
48553
+ ;// CONCATENATED MODULE: ./processor/utils.ts
48554
+ /**
48555
+ * Formats the hProperties of a node as a string, so they can be compiled back into JSX/MDX.
48556
+ * This currently sets all the values to a string since we process/compile the MDX on the fly
48557
+ * through the editor, and it'll throw errors over malformed JSX. TODO: fix this.
48558
+ *
48559
+ * @template T
48560
+ * @param {Node} node
48561
+ * @returns {string} formatted hProperties as JSX attributes
48562
+ */
48563
+ const formatHProps = (node) => {
48564
+ const hProps = getHProps(node);
48565
+ const hPropKeys = getHPropKeys(node);
48566
+ return hPropKeys.map(key => `${key}="${hProps[key]}"`).join(' ');
48567
+ };
48568
+ /**
48569
+ * Returns the hProperties of a node.
48570
+ *
48571
+ * @template T
48572
+ * @param {Node} node
48573
+ * @returns {T} hProperties
48574
+ */
48575
+ const getHProps = (node) => {
48576
+ var _a;
48577
+ const hProps = ((_a = node.data) === null || _a === void 0 ? void 0 : _a.hProperties) || {};
48578
+ return hProps;
48579
+ };
48580
+ /**
48581
+ * Returns array of hProperty keys.
48582
+ *
48583
+ * @template T
48584
+ * @param {Node} node
48585
+ * @returns {Array} array of hProperty keys
48586
+ */
48587
+ const getHPropKeys = (node) => {
48588
+ const hProps = getHProps(node);
48589
+ return Object.keys(hProps) || [];
48590
+ };
48591
+ /**
48592
+ * Gets the attributes of an MDX element and returns them as an object of hProperties.
48593
+ *
48594
+ * @template T
48595
+ * @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
48596
+ * @returns {T} object of hProperties
48597
+ */
48598
+ const getAttrs = (jsx) => jsx.attributes.reduce((memo, attr) => {
48599
+ if ('name' in attr) {
48600
+ memo[attr.name] = attr.value;
48601
+ }
48602
+ return memo;
48603
+ }, {});
48604
+ /**
48605
+ * Gets the children of an MDX element and returns them as an array of Text nodes.
48606
+ * Currently only being used by the HTML Block component, which only expects a single text node.
48607
+ *
48608
+ * @template T
48609
+ * @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
48610
+ * @returns {Array} array of child text nodes
48611
+ */
48612
+ const getChildren = (jsx) => jsx.children.reduce((memo, child, i) => {
48613
+ memo[i] = {
48614
+ type: 'text',
48615
+ value: child.value,
48616
+ position: child.position,
48617
+ };
48618
+ return memo;
48619
+ }, []);
48620
+ /**
48621
+ * Tests if a node is an MDX element.
48622
+ * TODO: Make this more extensible to all types of nodes. isElement(node, 'type' or ['type1', 'type2']), say
48623
+ *
48624
+ * @param {Node} node
48625
+ * @returns {(node is MdxJsxFlowElement | MdxJsxTextElement)}
48626
+ */
48627
+ const isMDXElement = (node) => {
48628
+ return ['mdxJsxFlowElement', 'mdxJsxTextElement'].includes(node.type);
48629
+ };
48630
+ /**
48631
+ * Takes an HTML string and formats it for display in the editor. Removes leading/trailing newlines
48632
+ * and unindents the HTML.
48633
+ *
48634
+ * @param {string} html
48635
+ * @returns {string} formatted HTML
48636
+ */
48637
+ const formatHTML = (html) => {
48638
+ // Remove leading/trailing backticks if present, since they're used to keep the HTML
48639
+ // from being parsed prematurely
48640
+ if (html.startsWith('`') && html.endsWith('`')) {
48641
+ html = html.slice(1, -1);
48642
+ }
48643
+ // Removes the leading/trailing newlines
48644
+ const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
48645
+ // // Get the number of spaces in the first line to determine the tab size
48646
+ // const tab = cleaned.match(/^\s*/)[0].length;
48647
+ // // Remove the first indentation level from each line
48648
+ // const tabRegex = new RegExp(`^\\s{${tab}}`, 'gm');
48649
+ // const unindented = cleaned.replace(tabRegex, '');
48650
+ return cleaned;
48651
+ };
48652
+ /**
48653
+ * Reformat HTML for the markdown/mdx by adding an indentation to each line. This assures that the
48654
+ * HTML is indentend properly within the HTMLBlock component when rendered in the markdown/mdx.
48655
+ *
48656
+ * @param {string} html
48657
+ * @param {number} [indent=2]
48658
+ * @returns {string} re-formatted HTML
48659
+ */
48660
+ const reformatHTML = (html, indent = 2) => {
48661
+ // Remove leading/trailing newlines
48662
+ const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
48663
+ // // Create a tab/indent with the specified number of spaces
48664
+ // const tab = ' '.repeat(indent);
48665
+ // // Indent each line of the HTML (converts to an array, indents each line, then joins back)
48666
+ // const indented = cleaned.split('\n').map((line: string) => `${tab}${line}`).join('\n');
48667
+ return cleaned;
48668
+ };
48669
+
48553
48670
  ;// CONCATENATED MODULE: ./processor/transform/images.ts
48554
48671
 
48555
48672
 
48556
- const imageTransformer = () => {
48557
- return (tree) => {
48558
- visit(tree, 'paragraph', (node, i, parent) => {
48559
- var _a;
48560
- // check if inline or already transformed
48561
- if (parent.type !== 'root' || ((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 1 || node.children[0].type !== 'image')
48562
- return;
48563
- const [{ alt, url, title }] = node.children;
48564
- const newNode = {
48565
- type: NodeTypes.imageBlock,
48566
- alt,
48567
- title,
48568
- url,
48569
- data: {
48570
- hName: 'img',
48571
- hProperties: Object.assign(Object.assign(Object.assign({}, (alt && { alt })), { src: url }), (title && { title })),
48572
- },
48573
- position: node.position,
48574
- };
48575
- parent.children.splice(i, 1, newNode);
48576
- });
48577
- };
48673
+
48674
+
48675
+ const imageTransformer = () => (tree) => {
48676
+ visit(tree, 'paragraph', (node, i, parent) => {
48677
+ var _a;
48678
+ // check if inline
48679
+ if (parent.type !== 'root' ||
48680
+ ((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 1 ||
48681
+ node.children[0].type !== 'image')
48682
+ return;
48683
+ const [{ alt, url, title }] = node.children;
48684
+ const newNode = {
48685
+ type: NodeTypes.imageBlock,
48686
+ alt,
48687
+ title,
48688
+ url,
48689
+ children: [],
48690
+ data: {
48691
+ hName: 'img',
48692
+ hProperties: Object.assign(Object.assign(Object.assign({}, (alt && { alt })), { src: url }), (title && { title })),
48693
+ },
48694
+ position: node.position,
48695
+ };
48696
+ parent.children.splice(i, 1, newNode);
48697
+ });
48698
+ const isImage = (node) => node.name === 'Image';
48699
+ visit(tree, isImage, (node) => {
48700
+ const attrs = getAttrs(node);
48701
+ if (attrs.caption) {
48702
+ node.children = lib_mdast(attrs.caption).children;
48703
+ }
48704
+ });
48705
+ return tree;
48578
48706
  };
48579
48707
  /* harmony default export */ const transform_images = (imageTransformer);
48580
48708
 
@@ -65564,6 +65692,7 @@ const gemojiTransformer = () => (tree) => {
65564
65692
 
65565
65693
  ;// CONCATENATED MODULE: ./processor/transform/inject-components.ts
65566
65694
 
65695
+
65567
65696
  const inject = ({ components } = {}) => (node, index, parent) => {
65568
65697
  if (!(node.name in components))
65569
65698
  return;
@@ -65571,140 +65700,23 @@ const inject = ({ components } = {}) => (node, index, parent) => {
65571
65700
  parent.children.splice(index, children.length, ...children);
65572
65701
  };
65573
65702
  const injectComponents = (opts) => () => tree => {
65574
- visit(tree, 'mdxJsxFlowElement', inject(opts));
65575
- visit(tree, 'mdxJsxTextElement', inject(opts));
65703
+ visit(tree, isMDXElement, inject(opts));
65576
65704
  return tree;
65577
65705
  };
65578
65706
  /* harmony default export */ const inject_components = (injectComponents);
65579
65707
 
65580
- ;// CONCATENATED MODULE: ./processor/utils.ts
65581
- /**
65582
- * Formats the hProperties of a node as a string, so they can be compiled back into JSX/MDX.
65583
- * This currently sets all the values to a string since we process/compile the MDX on the fly
65584
- * through the editor, and it'll throw errors over malformed JSX. TODO: fix this.
65585
- *
65586
- * @template T
65587
- * @param {Node} node
65588
- * @returns {string} formatted hProperties as JSX attributes
65589
- */
65590
- const formatHProps = (node) => {
65591
- const hProps = getHProps(node);
65592
- const hPropKeys = getHPropKeys(node);
65593
- return hPropKeys.map(key => `${key}="${hProps[key]}"`).join(' ');
65594
- };
65595
- /**
65596
- * Returns the hProperties of a node.
65597
- *
65598
- * @template T
65599
- * @param {Node} node
65600
- * @returns {T} hProperties
65601
- */
65602
- const getHProps = (node) => {
65603
- var _a;
65604
- const hProps = ((_a = node.data) === null || _a === void 0 ? void 0 : _a.hProperties) || {};
65605
- return hProps;
65606
- };
65607
- /**
65608
- * Returns array of hProperty keys.
65609
- *
65610
- * @template T
65611
- * @param {Node} node
65612
- * @returns {Array} array of hProperty keys
65613
- */
65614
- const getHPropKeys = (node) => {
65615
- const hProps = getHProps(node);
65616
- return Object.keys(hProps) || [];
65617
- };
65618
- /**
65619
- * Gets the attributes of an MDX element and returns them as an object of hProperties.
65620
- *
65621
- * @template T
65622
- * @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
65623
- * @returns {T} object of hProperties
65624
- */
65625
- const getAttrs = (jsx) => jsx.attributes.reduce((memo, attr) => {
65626
- if ('name' in attr) {
65627
- memo[attr.name] = attr.value;
65628
- }
65629
- return memo;
65630
- }, {});
65631
- /**
65632
- * Gets the children of an MDX element and returns them as an array of Text nodes.
65633
- * Currently only being used by the HTML Block component, which only expects a single text node.
65634
- *
65635
- * @template T
65636
- * @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
65637
- * @returns {Array} array of child text nodes
65638
- */
65639
- const getChildren = (jsx) => jsx.children.reduce((memo, child, i) => {
65640
- memo[i] = {
65641
- type: 'text',
65642
- value: child.value,
65643
- position: child.position,
65644
- };
65645
- return memo;
65646
- }, []);
65647
- /**
65648
- * Tests if a node is an MDX element.
65649
- * TODO: Make this more extensible to all types of nodes. isElement(node, 'type' or ['type1', 'type2']), say
65650
- *
65651
- * @param {Node} node
65652
- * @returns {(node is MdxJsxFlowElement | MdxJsxTextElement)}
65653
- */
65654
- const isMDXElement = (node) => {
65655
- return ['mdxJsxFlowElement', 'mdxJsxTextElement'].includes(node.type);
65656
- };
65657
- /**
65658
- * Takes an HTML string and formats it for display in the editor. Removes leading/trailing newlines
65659
- * and unindents the HTML.
65660
- *
65661
- * @param {string} html
65662
- * @returns {string} formatted HTML
65663
- */
65664
- const formatHTML = (html) => {
65665
- // Remove leading/trailing backticks if present, since they're used to keep the HTML
65666
- // from being parsed prematurely
65667
- if (html.startsWith('`') && html.endsWith('`')) {
65668
- html = html.slice(1, -1);
65669
- }
65670
- // Removes the leading/trailing newlines
65671
- const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
65672
- // // Get the number of spaces in the first line to determine the tab size
65673
- // const tab = cleaned.match(/^\s*/)[0].length;
65674
- // // Remove the first indentation level from each line
65675
- // const tabRegex = new RegExp(`^\\s{${tab}}`, 'gm');
65676
- // const unindented = cleaned.replace(tabRegex, '');
65677
- return cleaned;
65678
- };
65679
- /**
65680
- * Reformat HTML for the markdown/mdx by adding an indentation to each line. This assures that the
65681
- * HTML is indentend properly within the HTMLBlock component when rendered in the markdown/mdx.
65682
- *
65683
- * @param {string} html
65684
- * @param {number} [indent=2]
65685
- * @returns {string} re-formatted HTML
65686
- */
65687
- const reformatHTML = (html, indent = 2) => {
65688
- // Remove leading/trailing newlines
65689
- const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
65690
- // // Create a tab/indent with the specified number of spaces
65691
- // const tab = ' '.repeat(indent);
65692
- // // Indent each line of the HTML (converts to an array, indents each line, then joins back)
65693
- // const indented = cleaned.split('\n').map((line: string) => `${tab}${line}`).join('\n');
65694
- return cleaned;
65695
- };
65696
-
65697
65708
  ;// CONCATENATED MODULE: ./processor/transform/readme-components.ts
65698
65709
 
65699
65710
 
65700
65711
 
65712
+
65701
65713
  const readme_components_types = {
65702
65714
  Callout: NodeTypes['callout'],
65703
65715
  Code: 'code',
65704
65716
  CodeTabs: NodeTypes['codeTabs'],
65705
65717
  EmbedBlock: NodeTypes['embed-block'],
65706
65718
  Glossary: NodeTypes['glossary'],
65707
- ImageBlock: NodeTypes['image-block'],
65719
+ ImageBlock: NodeTypes.imageBlock,
65708
65720
  HTMLBlock: NodeTypes.htmlBlock,
65709
65721
  Table: 'table',
65710
65722
  Variable: NodeTypes['variable'],
@@ -65737,6 +65749,7 @@ const coerceJsxToMd = ({ components = {} } = {}) => (node, index, parent) => {
65737
65749
  const mdNode = {
65738
65750
  alt,
65739
65751
  position,
65752
+ children: attrs.caption ? lib_mdast(attrs.caption).children : node.children,
65740
65753
  title,
65741
65754
  type: NodeTypes.imageBlock,
65742
65755
  url: url || attrs.src,
package/dist/main.node.js CHANGED
@@ -14334,8 +14334,8 @@ const CreateHeading = (depth) => (props) => external_amd_react_commonjs_react_co
14334
14334
  ;// CONCATENATED MODULE: ./components/Image/index.tsx
14335
14335
 
14336
14336
  const Image = (Props) => {
14337
+ const { align = '', alt = '', border = false, caption, className = '', height = 'auto', src, title = '', width = 'auto', lazy = false, children, } = Props;
14337
14338
  const [lightbox, setLightbox] = external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.useState(false);
14338
- const { align = '', alt = '', border = false, caption, className = '', height = 'auto', src, title = '', width = 'auto', lazy = false, } = Props;
14339
14339
  if (className === 'emoji') {
14340
14340
  return external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("img", { src: src, width: width, height: height, title: title, alt: alt, loading: lazy ? 'lazy' : 'eager' });
14341
14341
  }
@@ -14366,7 +14366,7 @@ const Image = (Props) => {
14366
14366
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { className: "lightbox-inner" },
14367
14367
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("figure", null,
14368
14368
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("img", { src: src, width: width, height: height, title: title, className: `img img-align-center ${border ? 'border' : ''}`, alt: alt, loading: lazy ? 'lazy' : 'eager' }),
14369
- external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("figcaption", null, caption)))));
14369
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("figcaption", null, children || caption)))));
14370
14370
  }
14371
14371
  return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("p", null,
14372
14372
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { "aria-label": alt, className: `img lightbox ${lightbox ? 'open' : 'closed'}`, onClick: toggle, onKeyDown: handleKeyDown, role: 'button', tabIndex: 0 },
@@ -50003,31 +50003,159 @@ const embedTransformer = () => {
50003
50003
  };
50004
50004
  /* harmony default export */ const transform_embeds = (embedTransformer);
50005
50005
 
50006
+ ;// CONCATENATED MODULE: ./processor/utils.ts
50007
+ /**
50008
+ * Formats the hProperties of a node as a string, so they can be compiled back into JSX/MDX.
50009
+ * This currently sets all the values to a string since we process/compile the MDX on the fly
50010
+ * through the editor, and it'll throw errors over malformed JSX. TODO: fix this.
50011
+ *
50012
+ * @template T
50013
+ * @param {Node} node
50014
+ * @returns {string} formatted hProperties as JSX attributes
50015
+ */
50016
+ const formatHProps = (node) => {
50017
+ const hProps = getHProps(node);
50018
+ const hPropKeys = getHPropKeys(node);
50019
+ return hPropKeys.map(key => `${key}="${hProps[key]}"`).join(' ');
50020
+ };
50021
+ /**
50022
+ * Returns the hProperties of a node.
50023
+ *
50024
+ * @template T
50025
+ * @param {Node} node
50026
+ * @returns {T} hProperties
50027
+ */
50028
+ const getHProps = (node) => {
50029
+ var _a;
50030
+ const hProps = ((_a = node.data) === null || _a === void 0 ? void 0 : _a.hProperties) || {};
50031
+ return hProps;
50032
+ };
50033
+ /**
50034
+ * Returns array of hProperty keys.
50035
+ *
50036
+ * @template T
50037
+ * @param {Node} node
50038
+ * @returns {Array} array of hProperty keys
50039
+ */
50040
+ const getHPropKeys = (node) => {
50041
+ const hProps = getHProps(node);
50042
+ return Object.keys(hProps) || [];
50043
+ };
50044
+ /**
50045
+ * Gets the attributes of an MDX element and returns them as an object of hProperties.
50046
+ *
50047
+ * @template T
50048
+ * @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
50049
+ * @returns {T} object of hProperties
50050
+ */
50051
+ const getAttrs = (jsx) => jsx.attributes.reduce((memo, attr) => {
50052
+ if ('name' in attr) {
50053
+ memo[attr.name] = attr.value;
50054
+ }
50055
+ return memo;
50056
+ }, {});
50057
+ /**
50058
+ * Gets the children of an MDX element and returns them as an array of Text nodes.
50059
+ * Currently only being used by the HTML Block component, which only expects a single text node.
50060
+ *
50061
+ * @template T
50062
+ * @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
50063
+ * @returns {Array} array of child text nodes
50064
+ */
50065
+ const utils_getChildren = (jsx) => jsx.children.reduce((memo, child, i) => {
50066
+ memo[i] = {
50067
+ type: 'text',
50068
+ value: child.value,
50069
+ position: child.position,
50070
+ };
50071
+ return memo;
50072
+ }, []);
50073
+ /**
50074
+ * Tests if a node is an MDX element.
50075
+ * TODO: Make this more extensible to all types of nodes. isElement(node, 'type' or ['type1', 'type2']), say
50076
+ *
50077
+ * @param {Node} node
50078
+ * @returns {(node is MdxJsxFlowElement | MdxJsxTextElement)}
50079
+ */
50080
+ const isMDXElement = (node) => {
50081
+ return ['mdxJsxFlowElement', 'mdxJsxTextElement'].includes(node.type);
50082
+ };
50083
+ /**
50084
+ * Takes an HTML string and formats it for display in the editor. Removes leading/trailing newlines
50085
+ * and unindents the HTML.
50086
+ *
50087
+ * @param {string} html
50088
+ * @returns {string} formatted HTML
50089
+ */
50090
+ const formatHTML = (html) => {
50091
+ // Remove leading/trailing backticks if present, since they're used to keep the HTML
50092
+ // from being parsed prematurely
50093
+ if (html.startsWith('`') && html.endsWith('`')) {
50094
+ html = html.slice(1, -1);
50095
+ }
50096
+ // Removes the leading/trailing newlines
50097
+ const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
50098
+ // // Get the number of spaces in the first line to determine the tab size
50099
+ // const tab = cleaned.match(/^\s*/)[0].length;
50100
+ // // Remove the first indentation level from each line
50101
+ // const tabRegex = new RegExp(`^\\s{${tab}}`, 'gm');
50102
+ // const unindented = cleaned.replace(tabRegex, '');
50103
+ return cleaned;
50104
+ };
50105
+ /**
50106
+ * Reformat HTML for the markdown/mdx by adding an indentation to each line. This assures that the
50107
+ * HTML is indentend properly within the HTMLBlock component when rendered in the markdown/mdx.
50108
+ *
50109
+ * @param {string} html
50110
+ * @param {number} [indent=2]
50111
+ * @returns {string} re-formatted HTML
50112
+ */
50113
+ const reformatHTML = (html, indent = 2) => {
50114
+ // Remove leading/trailing newlines
50115
+ const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
50116
+ // // Create a tab/indent with the specified number of spaces
50117
+ // const tab = ' '.repeat(indent);
50118
+ // // Indent each line of the HTML (converts to an array, indents each line, then joins back)
50119
+ // const indented = cleaned.split('\n').map((line: string) => `${tab}${line}`).join('\n');
50120
+ return cleaned;
50121
+ };
50122
+
50006
50123
  ;// CONCATENATED MODULE: ./processor/transform/images.ts
50007
50124
 
50008
50125
 
50009
- const imageTransformer = () => {
50010
- return (tree) => {
50011
- visit(tree, 'paragraph', (node, i, parent) => {
50012
- var _a;
50013
- // check if inline or already transformed
50014
- if (parent.type !== 'root' || ((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 1 || node.children[0].type !== 'image')
50015
- return;
50016
- const [{ alt, url, title }] = node.children;
50017
- const newNode = {
50018
- type: NodeTypes.imageBlock,
50019
- alt,
50020
- title,
50021
- url,
50022
- data: {
50023
- hName: 'img',
50024
- hProperties: Object.assign(Object.assign(Object.assign({}, (alt && { alt })), { src: url }), (title && { title })),
50025
- },
50026
- position: node.position,
50027
- };
50028
- parent.children.splice(i, 1, newNode);
50029
- });
50030
- };
50126
+
50127
+
50128
+ const imageTransformer = () => (tree) => {
50129
+ visit(tree, 'paragraph', (node, i, parent) => {
50130
+ var _a;
50131
+ // check if inline
50132
+ if (parent.type !== 'root' ||
50133
+ ((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 1 ||
50134
+ node.children[0].type !== 'image')
50135
+ return;
50136
+ const [{ alt, url, title }] = node.children;
50137
+ const newNode = {
50138
+ type: NodeTypes.imageBlock,
50139
+ alt,
50140
+ title,
50141
+ url,
50142
+ children: [],
50143
+ data: {
50144
+ hName: 'img',
50145
+ hProperties: Object.assign(Object.assign(Object.assign({}, (alt && { alt })), { src: url }), (title && { title })),
50146
+ },
50147
+ position: node.position,
50148
+ };
50149
+ parent.children.splice(i, 1, newNode);
50150
+ });
50151
+ const isImage = (node) => node.name === 'Image';
50152
+ visit(tree, isImage, (node) => {
50153
+ const attrs = getAttrs(node);
50154
+ if (attrs.caption) {
50155
+ node.children = lib_mdast(attrs.caption).children;
50156
+ }
50157
+ });
50158
+ return tree;
50031
50159
  };
50032
50160
  /* harmony default export */ const transform_images = (imageTransformer);
50033
50161
 
@@ -67017,6 +67145,7 @@ const gemojiTransformer = () => (tree) => {
67017
67145
 
67018
67146
  ;// CONCATENATED MODULE: ./processor/transform/inject-components.ts
67019
67147
 
67148
+
67020
67149
  const inject = ({ components } = {}) => (node, index, parent) => {
67021
67150
  if (!(node.name in components))
67022
67151
  return;
@@ -67024,140 +67153,23 @@ const inject = ({ components } = {}) => (node, index, parent) => {
67024
67153
  parent.children.splice(index, children.length, ...children);
67025
67154
  };
67026
67155
  const injectComponents = (opts) => () => tree => {
67027
- visit(tree, 'mdxJsxFlowElement', inject(opts));
67028
- visit(tree, 'mdxJsxTextElement', inject(opts));
67156
+ visit(tree, isMDXElement, inject(opts));
67029
67157
  return tree;
67030
67158
  };
67031
67159
  /* harmony default export */ const inject_components = (injectComponents);
67032
67160
 
67033
- ;// CONCATENATED MODULE: ./processor/utils.ts
67034
- /**
67035
- * Formats the hProperties of a node as a string, so they can be compiled back into JSX/MDX.
67036
- * This currently sets all the values to a string since we process/compile the MDX on the fly
67037
- * through the editor, and it'll throw errors over malformed JSX. TODO: fix this.
67038
- *
67039
- * @template T
67040
- * @param {Node} node
67041
- * @returns {string} formatted hProperties as JSX attributes
67042
- */
67043
- const formatHProps = (node) => {
67044
- const hProps = getHProps(node);
67045
- const hPropKeys = getHPropKeys(node);
67046
- return hPropKeys.map(key => `${key}="${hProps[key]}"`).join(' ');
67047
- };
67048
- /**
67049
- * Returns the hProperties of a node.
67050
- *
67051
- * @template T
67052
- * @param {Node} node
67053
- * @returns {T} hProperties
67054
- */
67055
- const getHProps = (node) => {
67056
- var _a;
67057
- const hProps = ((_a = node.data) === null || _a === void 0 ? void 0 : _a.hProperties) || {};
67058
- return hProps;
67059
- };
67060
- /**
67061
- * Returns array of hProperty keys.
67062
- *
67063
- * @template T
67064
- * @param {Node} node
67065
- * @returns {Array} array of hProperty keys
67066
- */
67067
- const getHPropKeys = (node) => {
67068
- const hProps = getHProps(node);
67069
- return Object.keys(hProps) || [];
67070
- };
67071
- /**
67072
- * Gets the attributes of an MDX element and returns them as an object of hProperties.
67073
- *
67074
- * @template T
67075
- * @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
67076
- * @returns {T} object of hProperties
67077
- */
67078
- const getAttrs = (jsx) => jsx.attributes.reduce((memo, attr) => {
67079
- if ('name' in attr) {
67080
- memo[attr.name] = attr.value;
67081
- }
67082
- return memo;
67083
- }, {});
67084
- /**
67085
- * Gets the children of an MDX element and returns them as an array of Text nodes.
67086
- * Currently only being used by the HTML Block component, which only expects a single text node.
67087
- *
67088
- * @template T
67089
- * @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
67090
- * @returns {Array} array of child text nodes
67091
- */
67092
- const utils_getChildren = (jsx) => jsx.children.reduce((memo, child, i) => {
67093
- memo[i] = {
67094
- type: 'text',
67095
- value: child.value,
67096
- position: child.position,
67097
- };
67098
- return memo;
67099
- }, []);
67100
- /**
67101
- * Tests if a node is an MDX element.
67102
- * TODO: Make this more extensible to all types of nodes. isElement(node, 'type' or ['type1', 'type2']), say
67103
- *
67104
- * @param {Node} node
67105
- * @returns {(node is MdxJsxFlowElement | MdxJsxTextElement)}
67106
- */
67107
- const isMDXElement = (node) => {
67108
- return ['mdxJsxFlowElement', 'mdxJsxTextElement'].includes(node.type);
67109
- };
67110
- /**
67111
- * Takes an HTML string and formats it for display in the editor. Removes leading/trailing newlines
67112
- * and unindents the HTML.
67113
- *
67114
- * @param {string} html
67115
- * @returns {string} formatted HTML
67116
- */
67117
- const formatHTML = (html) => {
67118
- // Remove leading/trailing backticks if present, since they're used to keep the HTML
67119
- // from being parsed prematurely
67120
- if (html.startsWith('`') && html.endsWith('`')) {
67121
- html = html.slice(1, -1);
67122
- }
67123
- // Removes the leading/trailing newlines
67124
- const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
67125
- // // Get the number of spaces in the first line to determine the tab size
67126
- // const tab = cleaned.match(/^\s*/)[0].length;
67127
- // // Remove the first indentation level from each line
67128
- // const tabRegex = new RegExp(`^\\s{${tab}}`, 'gm');
67129
- // const unindented = cleaned.replace(tabRegex, '');
67130
- return cleaned;
67131
- };
67132
- /**
67133
- * Reformat HTML for the markdown/mdx by adding an indentation to each line. This assures that the
67134
- * HTML is indentend properly within the HTMLBlock component when rendered in the markdown/mdx.
67135
- *
67136
- * @param {string} html
67137
- * @param {number} [indent=2]
67138
- * @returns {string} re-formatted HTML
67139
- */
67140
- const reformatHTML = (html, indent = 2) => {
67141
- // Remove leading/trailing newlines
67142
- const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
67143
- // // Create a tab/indent with the specified number of spaces
67144
- // const tab = ' '.repeat(indent);
67145
- // // Indent each line of the HTML (converts to an array, indents each line, then joins back)
67146
- // const indented = cleaned.split('\n').map((line: string) => `${tab}${line}`).join('\n');
67147
- return cleaned;
67148
- };
67149
-
67150
67161
  ;// CONCATENATED MODULE: ./processor/transform/readme-components.ts
67151
67162
 
67152
67163
 
67153
67164
 
67165
+
67154
67166
  const readme_components_types = {
67155
67167
  Callout: NodeTypes['callout'],
67156
67168
  Code: 'code',
67157
67169
  CodeTabs: NodeTypes['codeTabs'],
67158
67170
  EmbedBlock: NodeTypes['embed-block'],
67159
67171
  Glossary: NodeTypes['glossary'],
67160
- ImageBlock: NodeTypes['image-block'],
67172
+ ImageBlock: NodeTypes.imageBlock,
67161
67173
  HTMLBlock: NodeTypes.htmlBlock,
67162
67174
  Table: 'table',
67163
67175
  Variable: NodeTypes['variable'],
@@ -67190,6 +67202,7 @@ const coerceJsxToMd = ({ components = {} } = {}) => (node, index, parent) => {
67190
67202
  const mdNode = {
67191
67203
  alt,
67192
67204
  position,
67205
+ children: attrs.caption ? lib_mdast(attrs.caption).children : node.children,
67193
67206
  title,
67194
67207
  type: NodeTypes.imageBlock,
67195
67208
  url: url || attrs.src,
@@ -1,3 +1,3 @@
1
1
  import { Node } from 'mdast';
2
- declare const imageTransformer: () => (tree: Node) => void;
2
+ declare const imageTransformer: () => (tree: Node) => Node;
3
3
  export default imageTransformer;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@readme/markdown",
3
3
  "description": "ReadMe's React-based Markdown parser",
4
4
  "author": "Rafe Goldberg <rafe@readme.io>",
5
- "version": "6.75.0-beta.63",
5
+ "version": "6.75.0-beta.64",
6
6
  "main": "dist/main.node.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "browser": "dist/main.js",