@readme/markdown 6.65.3 → 6.66.0-beta.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.
@@ -51,8 +51,8 @@ function Code(props) {
51
51
  dark: theme === 'dark',
52
52
  };
53
53
 
54
- const codeContent =
55
- syntaxHighlighter && children ? syntaxHighlighter(children[0], language, codeOpts) : children?.[0] || '';
54
+ const code = Array.isArray(children) ? children[0] : children;
55
+ const codeContent = syntaxHighlighter && children ? syntaxHighlighter(code, language, codeOpts) : code || '';
56
56
 
57
57
  return (
58
58
  <React.Fragment>
@@ -3,6 +3,22 @@ const PropTypes = require('prop-types');
3
3
  const React = require('react');
4
4
  const { useState } = require('react');
5
5
 
6
+ const traverseProps = (props, fn) => {
7
+ if (props?.children) {
8
+ if (props.children.forEach) {
9
+ props.children.forEach(child => {
10
+ if (child.props) {
11
+ traverseProps(child.props, fn);
12
+ }
13
+ });
14
+ } else {
15
+ fn(props.children.props);
16
+ }
17
+ }
18
+
19
+ fn(props);
20
+ };
21
+
6
22
  const CodeTabs = props => {
7
23
  const { children, theme } = props;
8
24
  const [activeIndex, setActiveIndex] = useState(0);
@@ -19,11 +35,17 @@ const CodeTabs = props => {
19
35
  setActiveIndex(index);
20
36
  }
21
37
 
38
+ const tabs = [];
39
+ traverseProps(props, childProps => {
40
+ if ('meta' in childProps || 'lang' in childProps) {
41
+ tabs.push({ meta: childProps.meta, lang: childProps.lang });
42
+ }
43
+ });
44
+
22
45
  return (
23
46
  <div className={`CodeTabs CodeTabs_initial theme-${theme}`}>
24
47
  <div className="CodeTabs-toolbar" role="tablist">
25
- {children.map(({ props: pre }, i) => {
26
- const { meta, lang } = pre.children[0].props;
48
+ {tabs.map(({ meta, lang }, i) => {
27
49
  /* istanbul ignore next */
28
50
  return (
29
51
  <button
@@ -56,5 +78,11 @@ function CreateCodeTabs({ theme }) {
56
78
  return props => <CodeTabs {...props} theme={theme} />;
57
79
  }
58
80
 
81
+ CreateCodeTabs.sanitize = sanitizeSchema => {
82
+ sanitizeSchema.attributes.div = ['className', 'tabs'];
83
+
84
+ return sanitizeSchema;
85
+ };
86
+
59
87
  module.exports = CreateCodeTabs;
60
88
  module.exports.CodeTabs = CodeTabs;
@@ -0,0 +1,30 @@
1
+ const PropTypes = require('prop-types');
2
+ const React = require('react');
3
+
4
+ /*
5
+ * To get around hast/html sanitation, we pass custom components through using
6
+ * className's. Then this Div component, can render the associated component
7
+ * instead. This used to be done with a custom `React.createElement`, but for
8
+ * mdx@v1.5, I don't see a way to customize that.
9
+ */
10
+
11
+ const Div = ({ components, ...props }) => {
12
+ if (Object.keys(components).includes(props.className)) {
13
+ const Component = components[props.className];
14
+ return <Component {...props} />;
15
+ }
16
+
17
+ // eslint-disable-next-line react/jsx-props-no-spreading
18
+ return <div {...props} />;
19
+ };
20
+
21
+ Div.propTypes = {
22
+ children: PropTypes.arrayOf(PropTypes.any),
23
+ className: PropTypes.string,
24
+ components: PropTypes.object,
25
+ };
26
+
27
+ module.exports =
28
+ (components, { theme }) =>
29
+ props =>
30
+ <Div components={components} theme={theme} {...props} />;
@@ -2,6 +2,7 @@ export { default as Anchor } from './Anchor';
2
2
  export { default as Callout } from './Callout';
3
3
  export { default as Code } from './Code';
4
4
  export { default as CodeTabs } from './CodeTabs';
5
+ export { default as Div } from './Div';
5
6
  export { default as Embed } from './Embed';
6
7
  export { default as GlossaryItem } from './GlossaryItem';
7
8
  export { default as HTMLBlock } from './HTMLBlock';