@readme/markdown 6.75.0-beta.63 → 6.75.0-beta.65
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/Image/index.tsx +5 -2
- package/dist/components/Image/index.d.ts +1 -0
- package/dist/main.js +197 -144
- package/dist/main.node.js +197 -144
- package/dist/processor/compile/compatibility.d.ts +17 -1
- package/dist/processor/transform/images.d.ts +1 -1
- package/dist/processor/utils.d.ts +7 -0
- package/package.json +1 -1
|
@@ -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>
|
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,168 @@ 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
|
+
return formatProps(hProps);
|
|
48566
|
+
};
|
|
48567
|
+
/**
|
|
48568
|
+
* Formats an object of props as a string.
|
|
48569
|
+
*
|
|
48570
|
+
* @param {Object} props
|
|
48571
|
+
* @returns {string}
|
|
48572
|
+
*/
|
|
48573
|
+
const formatProps = (props) => {
|
|
48574
|
+
const keys = Object.keys(props);
|
|
48575
|
+
return keys.map(key => `${key}="${props[key]}"`).join(' ');
|
|
48576
|
+
};
|
|
48577
|
+
/**
|
|
48578
|
+
* Returns the hProperties of a node.
|
|
48579
|
+
*
|
|
48580
|
+
* @template T
|
|
48581
|
+
* @param {Node} node
|
|
48582
|
+
* @returns {T} hProperties
|
|
48583
|
+
*/
|
|
48584
|
+
const getHProps = (node) => {
|
|
48585
|
+
var _a;
|
|
48586
|
+
const hProps = ((_a = node.data) === null || _a === void 0 ? void 0 : _a.hProperties) || {};
|
|
48587
|
+
return hProps;
|
|
48588
|
+
};
|
|
48589
|
+
/**
|
|
48590
|
+
* Returns array of hProperty keys.
|
|
48591
|
+
*
|
|
48592
|
+
* @template T
|
|
48593
|
+
* @param {Node} node
|
|
48594
|
+
* @returns {Array} array of hProperty keys
|
|
48595
|
+
*/
|
|
48596
|
+
const getHPropKeys = (node) => {
|
|
48597
|
+
const hProps = getHProps(node);
|
|
48598
|
+
return Object.keys(hProps) || [];
|
|
48599
|
+
};
|
|
48600
|
+
/**
|
|
48601
|
+
* Gets the attributes of an MDX element and returns them as an object of hProperties.
|
|
48602
|
+
*
|
|
48603
|
+
* @template T
|
|
48604
|
+
* @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
|
|
48605
|
+
* @returns {T} object of hProperties
|
|
48606
|
+
*/
|
|
48607
|
+
const getAttrs = (jsx) => jsx.attributes.reduce((memo, attr) => {
|
|
48608
|
+
if ('name' in attr) {
|
|
48609
|
+
memo[attr.name] = attr.value;
|
|
48610
|
+
}
|
|
48611
|
+
return memo;
|
|
48612
|
+
}, {});
|
|
48613
|
+
/**
|
|
48614
|
+
* Gets the children of an MDX element and returns them as an array of Text nodes.
|
|
48615
|
+
* Currently only being used by the HTML Block component, which only expects a single text node.
|
|
48616
|
+
*
|
|
48617
|
+
* @template T
|
|
48618
|
+
* @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
|
|
48619
|
+
* @returns {Array} array of child text nodes
|
|
48620
|
+
*/
|
|
48621
|
+
const getChildren = (jsx) => jsx.children.reduce((memo, child, i) => {
|
|
48622
|
+
memo[i] = {
|
|
48623
|
+
type: 'text',
|
|
48624
|
+
value: child.value,
|
|
48625
|
+
position: child.position,
|
|
48626
|
+
};
|
|
48627
|
+
return memo;
|
|
48628
|
+
}, []);
|
|
48629
|
+
/**
|
|
48630
|
+
* Tests if a node is an MDX element.
|
|
48631
|
+
* TODO: Make this more extensible to all types of nodes. isElement(node, 'type' or ['type1', 'type2']), say
|
|
48632
|
+
*
|
|
48633
|
+
* @param {Node} node
|
|
48634
|
+
* @returns {(node is MdxJsxFlowElement | MdxJsxTextElement)}
|
|
48635
|
+
*/
|
|
48636
|
+
const isMDXElement = (node) => {
|
|
48637
|
+
return ['mdxJsxFlowElement', 'mdxJsxTextElement'].includes(node.type);
|
|
48638
|
+
};
|
|
48639
|
+
/**
|
|
48640
|
+
* Takes an HTML string and formats it for display in the editor. Removes leading/trailing newlines
|
|
48641
|
+
* and unindents the HTML.
|
|
48642
|
+
*
|
|
48643
|
+
* @param {string} html
|
|
48644
|
+
* @returns {string} formatted HTML
|
|
48645
|
+
*/
|
|
48646
|
+
const formatHTML = (html) => {
|
|
48647
|
+
// Remove leading/trailing backticks if present, since they're used to keep the HTML
|
|
48648
|
+
// from being parsed prematurely
|
|
48649
|
+
if (html.startsWith('`') && html.endsWith('`')) {
|
|
48650
|
+
html = html.slice(1, -1);
|
|
48651
|
+
}
|
|
48652
|
+
// Removes the leading/trailing newlines
|
|
48653
|
+
const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
|
|
48654
|
+
// // Get the number of spaces in the first line to determine the tab size
|
|
48655
|
+
// const tab = cleaned.match(/^\s*/)[0].length;
|
|
48656
|
+
// // Remove the first indentation level from each line
|
|
48657
|
+
// const tabRegex = new RegExp(`^\\s{${tab}}`, 'gm');
|
|
48658
|
+
// const unindented = cleaned.replace(tabRegex, '');
|
|
48659
|
+
return cleaned;
|
|
48660
|
+
};
|
|
48661
|
+
/**
|
|
48662
|
+
* Reformat HTML for the markdown/mdx by adding an indentation to each line. This assures that the
|
|
48663
|
+
* HTML is indentend properly within the HTMLBlock component when rendered in the markdown/mdx.
|
|
48664
|
+
*
|
|
48665
|
+
* @param {string} html
|
|
48666
|
+
* @param {number} [indent=2]
|
|
48667
|
+
* @returns {string} re-formatted HTML
|
|
48668
|
+
*/
|
|
48669
|
+
const reformatHTML = (html, indent = 2) => {
|
|
48670
|
+
// Remove leading/trailing newlines
|
|
48671
|
+
const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
|
|
48672
|
+
// // Create a tab/indent with the specified number of spaces
|
|
48673
|
+
// const tab = ' '.repeat(indent);
|
|
48674
|
+
// // Indent each line of the HTML (converts to an array, indents each line, then joins back)
|
|
48675
|
+
// const indented = cleaned.split('\n').map((line: string) => `${tab}${line}`).join('\n');
|
|
48676
|
+
return cleaned;
|
|
48677
|
+
};
|
|
48678
|
+
|
|
48553
48679
|
;// CONCATENATED MODULE: ./processor/transform/images.ts
|
|
48554
48680
|
|
|
48555
48681
|
|
|
48556
|
-
|
|
48557
|
-
|
|
48558
|
-
|
|
48559
|
-
|
|
48560
|
-
|
|
48561
|
-
|
|
48562
|
-
|
|
48563
|
-
|
|
48564
|
-
|
|
48565
|
-
|
|
48566
|
-
|
|
48567
|
-
|
|
48568
|
-
|
|
48569
|
-
|
|
48570
|
-
|
|
48571
|
-
|
|
48572
|
-
|
|
48573
|
-
|
|
48574
|
-
|
|
48575
|
-
|
|
48576
|
-
|
|
48577
|
-
|
|
48682
|
+
|
|
48683
|
+
|
|
48684
|
+
const imageTransformer = () => (tree) => {
|
|
48685
|
+
visit(tree, 'paragraph', (node, i, parent) => {
|
|
48686
|
+
var _a;
|
|
48687
|
+
// check if inline
|
|
48688
|
+
if (parent.type !== 'root' ||
|
|
48689
|
+
((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 1 ||
|
|
48690
|
+
node.children[0].type !== 'image')
|
|
48691
|
+
return;
|
|
48692
|
+
const [{ alt, url, title }] = node.children;
|
|
48693
|
+
const newNode = {
|
|
48694
|
+
type: NodeTypes.imageBlock,
|
|
48695
|
+
alt,
|
|
48696
|
+
title,
|
|
48697
|
+
url,
|
|
48698
|
+
children: [],
|
|
48699
|
+
data: {
|
|
48700
|
+
hName: 'img',
|
|
48701
|
+
hProperties: Object.assign(Object.assign(Object.assign({}, (alt && { alt })), { src: url }), (title && { title })),
|
|
48702
|
+
},
|
|
48703
|
+
position: node.position,
|
|
48704
|
+
};
|
|
48705
|
+
parent.children.splice(i, 1, newNode);
|
|
48706
|
+
});
|
|
48707
|
+
const isImage = (node) => node.name === 'Image';
|
|
48708
|
+
visit(tree, isImage, (node) => {
|
|
48709
|
+
const attrs = getAttrs(node);
|
|
48710
|
+
if (attrs.caption) {
|
|
48711
|
+
node.children = lib_mdast(attrs.caption).children;
|
|
48712
|
+
}
|
|
48713
|
+
});
|
|
48714
|
+
return tree;
|
|
48578
48715
|
};
|
|
48579
48716
|
/* harmony default export */ const transform_images = (imageTransformer);
|
|
48580
48717
|
|
|
@@ -65564,6 +65701,7 @@ const gemojiTransformer = () => (tree) => {
|
|
|
65564
65701
|
|
|
65565
65702
|
;// CONCATENATED MODULE: ./processor/transform/inject-components.ts
|
|
65566
65703
|
|
|
65704
|
+
|
|
65567
65705
|
const inject = ({ components } = {}) => (node, index, parent) => {
|
|
65568
65706
|
if (!(node.name in components))
|
|
65569
65707
|
return;
|
|
@@ -65571,140 +65709,23 @@ const inject = ({ components } = {}) => (node, index, parent) => {
|
|
|
65571
65709
|
parent.children.splice(index, children.length, ...children);
|
|
65572
65710
|
};
|
|
65573
65711
|
const injectComponents = (opts) => () => tree => {
|
|
65574
|
-
visit(tree,
|
|
65575
|
-
visit(tree, 'mdxJsxTextElement', inject(opts));
|
|
65712
|
+
visit(tree, isMDXElement, inject(opts));
|
|
65576
65713
|
return tree;
|
|
65577
65714
|
};
|
|
65578
65715
|
/* harmony default export */ const inject_components = (injectComponents);
|
|
65579
65716
|
|
|
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
65717
|
;// CONCATENATED MODULE: ./processor/transform/readme-components.ts
|
|
65698
65718
|
|
|
65699
65719
|
|
|
65700
65720
|
|
|
65721
|
+
|
|
65701
65722
|
const readme_components_types = {
|
|
65702
65723
|
Callout: NodeTypes['callout'],
|
|
65703
65724
|
Code: 'code',
|
|
65704
65725
|
CodeTabs: NodeTypes['codeTabs'],
|
|
65705
65726
|
EmbedBlock: NodeTypes['embed-block'],
|
|
65706
65727
|
Glossary: NodeTypes['glossary'],
|
|
65707
|
-
ImageBlock: NodeTypes
|
|
65728
|
+
ImageBlock: NodeTypes.imageBlock,
|
|
65708
65729
|
HTMLBlock: NodeTypes.htmlBlock,
|
|
65709
65730
|
Table: 'table',
|
|
65710
65731
|
Variable: NodeTypes['variable'],
|
|
@@ -65737,6 +65758,7 @@ const coerceJsxToMd = ({ components = {} } = {}) => (node, index, parent) => {
|
|
|
65737
65758
|
const mdNode = {
|
|
65738
65759
|
alt,
|
|
65739
65760
|
position,
|
|
65761
|
+
children: attrs.caption ? lib_mdast(attrs.caption).children : node.children,
|
|
65740
65762
|
title,
|
|
65741
65763
|
type: NodeTypes.imageBlock,
|
|
65742
65764
|
url: url || attrs.src,
|
|
@@ -94376,6 +94398,19 @@ function toXml(tree, options) {
|
|
|
94376
94398
|
}
|
|
94377
94399
|
|
|
94378
94400
|
;// CONCATENATED MODULE: ./processor/compile/compatibility.ts
|
|
94401
|
+
var compatibility_rest = (undefined && undefined.__rest) || function (s, e) {
|
|
94402
|
+
var t = {};
|
|
94403
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
94404
|
+
t[p] = s[p];
|
|
94405
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
94406
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
94407
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
94408
|
+
t[p[i]] = s[p[i]];
|
|
94409
|
+
}
|
|
94410
|
+
return t;
|
|
94411
|
+
};
|
|
94412
|
+
|
|
94413
|
+
|
|
94379
94414
|
|
|
94380
94415
|
|
|
94381
94416
|
|
|
@@ -94394,6 +94429,17 @@ const compatibility_html = (node) => {
|
|
|
94394
94429
|
const xml = toXml(xast, { closeEmptyElements: true });
|
|
94395
94430
|
return xml.replace(/<html.*<body>(.*)<\/body><\/html>/ms, '$1');
|
|
94396
94431
|
};
|
|
94432
|
+
const figureToImageBlock = (node) => {
|
|
94433
|
+
const _a = node.children.find((child) => child.type === 'image'), { align, width, src, alt, title } = _a, image = compatibility_rest(_a, ["align", "width", "src", "alt", "title"]);
|
|
94434
|
+
const { className } = image.data.hProperties;
|
|
94435
|
+
const figcaption = node.children.find((child) => child.type === 'figcaption');
|
|
94436
|
+
const caption = figcaption ? toMarkdown({
|
|
94437
|
+
type: 'paragraph',
|
|
94438
|
+
children: figcaption.children,
|
|
94439
|
+
}).trim() : null;
|
|
94440
|
+
const attributes = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (align && { align })), (alt && { alt })), (className && { border: className === 'border' })), (caption && { caption })), (title && { title })), (width && { width })), { src });
|
|
94441
|
+
return `<Image ${formatProps(attributes)} />`;
|
|
94442
|
+
};
|
|
94397
94443
|
const compatibility = (node) => {
|
|
94398
94444
|
var _a, _b;
|
|
94399
94445
|
switch (node.type) {
|
|
@@ -94407,6 +94453,11 @@ const compatibility = (node) => {
|
|
|
94407
94453
|
return compatibility_html(node);
|
|
94408
94454
|
case 'escape':
|
|
94409
94455
|
return `\\${node.value}`;
|
|
94456
|
+
case 'figure':
|
|
94457
|
+
return figureToImageBlock(node);
|
|
94458
|
+
case 'embed':
|
|
94459
|
+
const attributes = formatHProps(node);
|
|
94460
|
+
return `<Embed ${attributes} />`;
|
|
94410
94461
|
default:
|
|
94411
94462
|
throw new Error('Unhandled node type!');
|
|
94412
94463
|
}
|
|
@@ -94440,7 +94491,9 @@ function compilers() {
|
|
|
94440
94491
|
[NodeTypes.imageBlock]: compile_image,
|
|
94441
94492
|
[NodeTypes.reusableContent]: compile_compatibility,
|
|
94442
94493
|
[NodeTypes.variable]: compile_variable,
|
|
94494
|
+
embed: compile_compatibility,
|
|
94443
94495
|
escape: compile_compatibility,
|
|
94496
|
+
figure: compile_compatibility,
|
|
94444
94497
|
html: compile_compatibility,
|
|
94445
94498
|
};
|
|
94446
94499
|
toMarkdownExtensions.push({ extensions: [{ handlers }] });
|
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,168 @@ 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
|
+
return formatProps(hProps);
|
|
50019
|
+
};
|
|
50020
|
+
/**
|
|
50021
|
+
* Formats an object of props as a string.
|
|
50022
|
+
*
|
|
50023
|
+
* @param {Object} props
|
|
50024
|
+
* @returns {string}
|
|
50025
|
+
*/
|
|
50026
|
+
const formatProps = (props) => {
|
|
50027
|
+
const keys = Object.keys(props);
|
|
50028
|
+
return keys.map(key => `${key}="${props[key]}"`).join(' ');
|
|
50029
|
+
};
|
|
50030
|
+
/**
|
|
50031
|
+
* Returns the hProperties of a node.
|
|
50032
|
+
*
|
|
50033
|
+
* @template T
|
|
50034
|
+
* @param {Node} node
|
|
50035
|
+
* @returns {T} hProperties
|
|
50036
|
+
*/
|
|
50037
|
+
const getHProps = (node) => {
|
|
50038
|
+
var _a;
|
|
50039
|
+
const hProps = ((_a = node.data) === null || _a === void 0 ? void 0 : _a.hProperties) || {};
|
|
50040
|
+
return hProps;
|
|
50041
|
+
};
|
|
50042
|
+
/**
|
|
50043
|
+
* Returns array of hProperty keys.
|
|
50044
|
+
*
|
|
50045
|
+
* @template T
|
|
50046
|
+
* @param {Node} node
|
|
50047
|
+
* @returns {Array} array of hProperty keys
|
|
50048
|
+
*/
|
|
50049
|
+
const getHPropKeys = (node) => {
|
|
50050
|
+
const hProps = getHProps(node);
|
|
50051
|
+
return Object.keys(hProps) || [];
|
|
50052
|
+
};
|
|
50053
|
+
/**
|
|
50054
|
+
* Gets the attributes of an MDX element and returns them as an object of hProperties.
|
|
50055
|
+
*
|
|
50056
|
+
* @template T
|
|
50057
|
+
* @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
|
|
50058
|
+
* @returns {T} object of hProperties
|
|
50059
|
+
*/
|
|
50060
|
+
const getAttrs = (jsx) => jsx.attributes.reduce((memo, attr) => {
|
|
50061
|
+
if ('name' in attr) {
|
|
50062
|
+
memo[attr.name] = attr.value;
|
|
50063
|
+
}
|
|
50064
|
+
return memo;
|
|
50065
|
+
}, {});
|
|
50066
|
+
/**
|
|
50067
|
+
* Gets the children of an MDX element and returns them as an array of Text nodes.
|
|
50068
|
+
* Currently only being used by the HTML Block component, which only expects a single text node.
|
|
50069
|
+
*
|
|
50070
|
+
* @template T
|
|
50071
|
+
* @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
|
|
50072
|
+
* @returns {Array} array of child text nodes
|
|
50073
|
+
*/
|
|
50074
|
+
const utils_getChildren = (jsx) => jsx.children.reduce((memo, child, i) => {
|
|
50075
|
+
memo[i] = {
|
|
50076
|
+
type: 'text',
|
|
50077
|
+
value: child.value,
|
|
50078
|
+
position: child.position,
|
|
50079
|
+
};
|
|
50080
|
+
return memo;
|
|
50081
|
+
}, []);
|
|
50082
|
+
/**
|
|
50083
|
+
* Tests if a node is an MDX element.
|
|
50084
|
+
* TODO: Make this more extensible to all types of nodes. isElement(node, 'type' or ['type1', 'type2']), say
|
|
50085
|
+
*
|
|
50086
|
+
* @param {Node} node
|
|
50087
|
+
* @returns {(node is MdxJsxFlowElement | MdxJsxTextElement)}
|
|
50088
|
+
*/
|
|
50089
|
+
const isMDXElement = (node) => {
|
|
50090
|
+
return ['mdxJsxFlowElement', 'mdxJsxTextElement'].includes(node.type);
|
|
50091
|
+
};
|
|
50092
|
+
/**
|
|
50093
|
+
* Takes an HTML string and formats it for display in the editor. Removes leading/trailing newlines
|
|
50094
|
+
* and unindents the HTML.
|
|
50095
|
+
*
|
|
50096
|
+
* @param {string} html
|
|
50097
|
+
* @returns {string} formatted HTML
|
|
50098
|
+
*/
|
|
50099
|
+
const formatHTML = (html) => {
|
|
50100
|
+
// Remove leading/trailing backticks if present, since they're used to keep the HTML
|
|
50101
|
+
// from being parsed prematurely
|
|
50102
|
+
if (html.startsWith('`') && html.endsWith('`')) {
|
|
50103
|
+
html = html.slice(1, -1);
|
|
50104
|
+
}
|
|
50105
|
+
// Removes the leading/trailing newlines
|
|
50106
|
+
const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
|
|
50107
|
+
// // Get the number of spaces in the first line to determine the tab size
|
|
50108
|
+
// const tab = cleaned.match(/^\s*/)[0].length;
|
|
50109
|
+
// // Remove the first indentation level from each line
|
|
50110
|
+
// const tabRegex = new RegExp(`^\\s{${tab}}`, 'gm');
|
|
50111
|
+
// const unindented = cleaned.replace(tabRegex, '');
|
|
50112
|
+
return cleaned;
|
|
50113
|
+
};
|
|
50114
|
+
/**
|
|
50115
|
+
* Reformat HTML for the markdown/mdx by adding an indentation to each line. This assures that the
|
|
50116
|
+
* HTML is indentend properly within the HTMLBlock component when rendered in the markdown/mdx.
|
|
50117
|
+
*
|
|
50118
|
+
* @param {string} html
|
|
50119
|
+
* @param {number} [indent=2]
|
|
50120
|
+
* @returns {string} re-formatted HTML
|
|
50121
|
+
*/
|
|
50122
|
+
const reformatHTML = (html, indent = 2) => {
|
|
50123
|
+
// Remove leading/trailing newlines
|
|
50124
|
+
const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
|
|
50125
|
+
// // Create a tab/indent with the specified number of spaces
|
|
50126
|
+
// const tab = ' '.repeat(indent);
|
|
50127
|
+
// // Indent each line of the HTML (converts to an array, indents each line, then joins back)
|
|
50128
|
+
// const indented = cleaned.split('\n').map((line: string) => `${tab}${line}`).join('\n');
|
|
50129
|
+
return cleaned;
|
|
50130
|
+
};
|
|
50131
|
+
|
|
50006
50132
|
;// CONCATENATED MODULE: ./processor/transform/images.ts
|
|
50007
50133
|
|
|
50008
50134
|
|
|
50009
|
-
|
|
50010
|
-
|
|
50011
|
-
|
|
50012
|
-
|
|
50013
|
-
|
|
50014
|
-
|
|
50015
|
-
|
|
50016
|
-
|
|
50017
|
-
|
|
50018
|
-
|
|
50019
|
-
|
|
50020
|
-
|
|
50021
|
-
|
|
50022
|
-
|
|
50023
|
-
|
|
50024
|
-
|
|
50025
|
-
|
|
50026
|
-
|
|
50027
|
-
|
|
50028
|
-
|
|
50029
|
-
|
|
50030
|
-
|
|
50135
|
+
|
|
50136
|
+
|
|
50137
|
+
const imageTransformer = () => (tree) => {
|
|
50138
|
+
visit(tree, 'paragraph', (node, i, parent) => {
|
|
50139
|
+
var _a;
|
|
50140
|
+
// check if inline
|
|
50141
|
+
if (parent.type !== 'root' ||
|
|
50142
|
+
((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 1 ||
|
|
50143
|
+
node.children[0].type !== 'image')
|
|
50144
|
+
return;
|
|
50145
|
+
const [{ alt, url, title }] = node.children;
|
|
50146
|
+
const newNode = {
|
|
50147
|
+
type: NodeTypes.imageBlock,
|
|
50148
|
+
alt,
|
|
50149
|
+
title,
|
|
50150
|
+
url,
|
|
50151
|
+
children: [],
|
|
50152
|
+
data: {
|
|
50153
|
+
hName: 'img',
|
|
50154
|
+
hProperties: Object.assign(Object.assign(Object.assign({}, (alt && { alt })), { src: url }), (title && { title })),
|
|
50155
|
+
},
|
|
50156
|
+
position: node.position,
|
|
50157
|
+
};
|
|
50158
|
+
parent.children.splice(i, 1, newNode);
|
|
50159
|
+
});
|
|
50160
|
+
const isImage = (node) => node.name === 'Image';
|
|
50161
|
+
visit(tree, isImage, (node) => {
|
|
50162
|
+
const attrs = getAttrs(node);
|
|
50163
|
+
if (attrs.caption) {
|
|
50164
|
+
node.children = lib_mdast(attrs.caption).children;
|
|
50165
|
+
}
|
|
50166
|
+
});
|
|
50167
|
+
return tree;
|
|
50031
50168
|
};
|
|
50032
50169
|
/* harmony default export */ const transform_images = (imageTransformer);
|
|
50033
50170
|
|
|
@@ -67017,6 +67154,7 @@ const gemojiTransformer = () => (tree) => {
|
|
|
67017
67154
|
|
|
67018
67155
|
;// CONCATENATED MODULE: ./processor/transform/inject-components.ts
|
|
67019
67156
|
|
|
67157
|
+
|
|
67020
67158
|
const inject = ({ components } = {}) => (node, index, parent) => {
|
|
67021
67159
|
if (!(node.name in components))
|
|
67022
67160
|
return;
|
|
@@ -67024,140 +67162,23 @@ const inject = ({ components } = {}) => (node, index, parent) => {
|
|
|
67024
67162
|
parent.children.splice(index, children.length, ...children);
|
|
67025
67163
|
};
|
|
67026
67164
|
const injectComponents = (opts) => () => tree => {
|
|
67027
|
-
visit(tree,
|
|
67028
|
-
visit(tree, 'mdxJsxTextElement', inject(opts));
|
|
67165
|
+
visit(tree, isMDXElement, inject(opts));
|
|
67029
67166
|
return tree;
|
|
67030
67167
|
};
|
|
67031
67168
|
/* harmony default export */ const inject_components = (injectComponents);
|
|
67032
67169
|
|
|
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
67170
|
;// CONCATENATED MODULE: ./processor/transform/readme-components.ts
|
|
67151
67171
|
|
|
67152
67172
|
|
|
67153
67173
|
|
|
67174
|
+
|
|
67154
67175
|
const readme_components_types = {
|
|
67155
67176
|
Callout: NodeTypes['callout'],
|
|
67156
67177
|
Code: 'code',
|
|
67157
67178
|
CodeTabs: NodeTypes['codeTabs'],
|
|
67158
67179
|
EmbedBlock: NodeTypes['embed-block'],
|
|
67159
67180
|
Glossary: NodeTypes['glossary'],
|
|
67160
|
-
ImageBlock: NodeTypes
|
|
67181
|
+
ImageBlock: NodeTypes.imageBlock,
|
|
67161
67182
|
HTMLBlock: NodeTypes.htmlBlock,
|
|
67162
67183
|
Table: 'table',
|
|
67163
67184
|
Variable: NodeTypes['variable'],
|
|
@@ -67190,6 +67211,7 @@ const coerceJsxToMd = ({ components = {} } = {}) => (node, index, parent) => {
|
|
|
67190
67211
|
const mdNode = {
|
|
67191
67212
|
alt,
|
|
67192
67213
|
position,
|
|
67214
|
+
children: attrs.caption ? lib_mdast(attrs.caption).children : node.children,
|
|
67193
67215
|
title,
|
|
67194
67216
|
type: NodeTypes.imageBlock,
|
|
67195
67217
|
url: url || attrs.src,
|
|
@@ -95829,6 +95851,19 @@ function toXml(tree, options) {
|
|
|
95829
95851
|
}
|
|
95830
95852
|
|
|
95831
95853
|
;// CONCATENATED MODULE: ./processor/compile/compatibility.ts
|
|
95854
|
+
var compatibility_rest = (undefined && undefined.__rest) || function (s, e) {
|
|
95855
|
+
var t = {};
|
|
95856
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
95857
|
+
t[p] = s[p];
|
|
95858
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
95859
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
95860
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
95861
|
+
t[p[i]] = s[p[i]];
|
|
95862
|
+
}
|
|
95863
|
+
return t;
|
|
95864
|
+
};
|
|
95865
|
+
|
|
95866
|
+
|
|
95832
95867
|
|
|
95833
95868
|
|
|
95834
95869
|
|
|
@@ -95847,6 +95882,17 @@ const compatibility_html = (node) => {
|
|
|
95847
95882
|
const xml = toXml(xast, { closeEmptyElements: true });
|
|
95848
95883
|
return xml.replace(/<html.*<body>(.*)<\/body><\/html>/ms, '$1');
|
|
95849
95884
|
};
|
|
95885
|
+
const figureToImageBlock = (node) => {
|
|
95886
|
+
const _a = node.children.find((child) => child.type === 'image'), { align, width, src, alt, title } = _a, image = compatibility_rest(_a, ["align", "width", "src", "alt", "title"]);
|
|
95887
|
+
const { className } = image.data.hProperties;
|
|
95888
|
+
const figcaption = node.children.find((child) => child.type === 'figcaption');
|
|
95889
|
+
const caption = figcaption ? toMarkdown({
|
|
95890
|
+
type: 'paragraph',
|
|
95891
|
+
children: figcaption.children,
|
|
95892
|
+
}).trim() : null;
|
|
95893
|
+
const attributes = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (align && { align })), (alt && { alt })), (className && { border: className === 'border' })), (caption && { caption })), (title && { title })), (width && { width })), { src });
|
|
95894
|
+
return `<Image ${formatProps(attributes)} />`;
|
|
95895
|
+
};
|
|
95850
95896
|
const compatibility = (node) => {
|
|
95851
95897
|
var _a, _b;
|
|
95852
95898
|
switch (node.type) {
|
|
@@ -95860,6 +95906,11 @@ const compatibility = (node) => {
|
|
|
95860
95906
|
return compatibility_html(node);
|
|
95861
95907
|
case 'escape':
|
|
95862
95908
|
return `\\${node.value}`;
|
|
95909
|
+
case 'figure':
|
|
95910
|
+
return figureToImageBlock(node);
|
|
95911
|
+
case 'embed':
|
|
95912
|
+
const attributes = formatHProps(node);
|
|
95913
|
+
return `<Embed ${attributes} />`;
|
|
95863
95914
|
default:
|
|
95864
95915
|
throw new Error('Unhandled node type!');
|
|
95865
95916
|
}
|
|
@@ -95893,7 +95944,9 @@ function compilers() {
|
|
|
95893
95944
|
[NodeTypes.imageBlock]: compile_image,
|
|
95894
95945
|
[NodeTypes.reusableContent]: compile_compatibility,
|
|
95895
95946
|
[NodeTypes.variable]: compile_variable,
|
|
95947
|
+
embed: compile_compatibility,
|
|
95896
95948
|
escape: compile_compatibility,
|
|
95949
|
+
figure: compile_compatibility,
|
|
95897
95950
|
html: compile_compatibility,
|
|
95898
95951
|
};
|
|
95899
95952
|
toMarkdownExtensions.push({ extensions: [{ handlers }] });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Html } from 'mdast';
|
|
1
|
+
import { Html, Image } from 'mdast';
|
|
2
2
|
import { NodeTypes } from '../../enums';
|
|
3
3
|
type CompatNodes = {
|
|
4
4
|
type: NodeTypes.glossary;
|
|
@@ -19,9 +19,25 @@ type CompatNodes = {
|
|
|
19
19
|
} | {
|
|
20
20
|
type: NodeTypes.reusableContent;
|
|
21
21
|
tag: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: 'embed';
|
|
24
|
+
data: {
|
|
25
|
+
hProperties: {
|
|
26
|
+
[key: string]: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
22
29
|
} | {
|
|
23
30
|
type: 'escape';
|
|
24
31
|
value: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'figure';
|
|
34
|
+
children: [Image, {
|
|
35
|
+
type: 'figcaption';
|
|
36
|
+
children: [{
|
|
37
|
+
type: 'text';
|
|
38
|
+
value: string;
|
|
39
|
+
}];
|
|
40
|
+
}];
|
|
25
41
|
} | Html;
|
|
26
42
|
declare const compatibility: (node: CompatNodes) => string;
|
|
27
43
|
export default compatibility;
|
|
@@ -10,6 +10,13 @@ import { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx';
|
|
|
10
10
|
* @returns {string} formatted hProperties as JSX attributes
|
|
11
11
|
*/
|
|
12
12
|
export declare const formatHProps: <T>(node: Node) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Formats an object of props as a string.
|
|
15
|
+
*
|
|
16
|
+
* @param {Object} props
|
|
17
|
+
* @returns {string}
|
|
18
|
+
*/
|
|
19
|
+
export declare const formatProps: (props: Object) => string;
|
|
13
20
|
/**
|
|
14
21
|
* Returns the hProperties of a node.
|
|
15
22
|
*
|
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.
|
|
5
|
+
"version": "6.75.0-beta.65",
|
|
6
6
|
"main": "dist/main.node.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"browser": "dist/main.js",
|