@readme/markdown 9.1.5 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import copy from 'copy-to-clipboard';
2
2
  import React, { createRef, useContext } from 'react';
3
3
 
4
+ import CodeOptsContext from '../../contexts/CodeOpts';
4
5
  import ThemeContext from '../../contexts/Theme';
5
6
 
6
7
  // Only load CodeMirror in the browser, for SSR
@@ -53,8 +54,9 @@ interface CodeProps {
53
54
  }
54
55
 
55
56
  const Code = (props: CodeProps) => {
56
- const { children, copyButtons, lang, value } = props;
57
+ const { children, lang, value } = props;
57
58
  const theme = useContext(ThemeContext);
59
+ const copyButtons = useContext(CodeOptsContext) || props.copyButtons;
58
60
 
59
61
  const language = canonicalLanguage(lang);
60
62
 
@@ -1,5 +1,4 @@
1
1
  import React, { useEffect } from 'react';
2
- import { renderToStaticMarkup } from 'react-dom/server';
3
2
 
4
3
  const MATCH_SCRIPT_TAGS = /<script\b[^>]*>([\s\S]*?)<\/script *>\n?/gim;
5
4
 
@@ -21,11 +20,14 @@ interface Props {
21
20
  }
22
21
 
23
22
  const HTMLBlock = ({ children = '', runScripts, safeMode = false }: Props) => {
24
- let html = children;
23
+ if (typeof children !== 'string') {
24
+ throw new TypeError('HTMLBlock: children must be a string');
25
+ }
26
+
27
+ const html = children;
25
28
  // eslint-disable-next-line no-param-reassign
26
29
  runScripts = typeof runScripts !== 'boolean' ? runScripts === 'true' : runScripts;
27
30
 
28
- if (typeof html !== 'string') html = renderToStaticMarkup(html);
29
31
  const [cleanedHtml, exec] = extractScripts(html);
30
32
 
31
33
  useEffect(() => {
@@ -0,0 +1,2 @@
1
+ declare const CodeOptsContext: import("react").Context<boolean>;
2
+ export default CodeOptsContext;
@@ -1,5 +1,5 @@
1
1
  import type { RunOpts } from '../lib/run';
2
2
  import React from 'react';
3
- type Props = Pick<RunOpts, 'baseUrl' | 'terms' | 'theme' | 'variables'> & React.PropsWithChildren;
4
- declare const Contexts: ({ children, terms, variables, baseUrl, theme }: Props) => React.ReactNode;
3
+ type Props = Pick<RunOpts, 'baseUrl' | 'copyButtons' | 'terms' | 'theme' | 'variables'> & React.PropsWithChildren;
4
+ declare const Contexts: ({ children, terms, variables, baseUrl, theme, copyButtons }: Props) => React.ReactNode;
5
5
  export default Contexts;
package/dist/lib/run.d.ts CHANGED
@@ -5,6 +5,7 @@ import type { RunOptions } from '@mdx-js/mdx';
5
5
  export type RunOpts = Omit<RunOptions, 'Fragment'> & {
6
6
  baseUrl?: string;
7
7
  components?: CustomComponents;
8
+ copyButtons?: boolean;
8
9
  imports?: Record<string, unknown>;
9
10
  terms?: GlossaryTerm[];
10
11
  theme?: 'dark' | 'light';