@readme/markdown 6.75.0-beta.26 → 6.75.0-beta.28

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.
@@ -24,10 +24,4 @@ const Callout = (props: Props) => {
24
24
  );
25
25
  };
26
26
 
27
- Callout.sanitize = sanitizeSchema => {
28
- sanitizeSchema.attributes['rdme-callout'] = ['icon', 'theme', 'heading'];
29
-
30
- return sanitizeSchema;
31
- };
32
-
33
27
  export default Callout;
@@ -0,0 +1,73 @@
1
+ import copy from 'copy-to-clipboard';
2
+ import React, { createRef } from 'react';
3
+
4
+ // Only load CodeMirror in the browser, for SSR
5
+ // apps. Necessary because of people like this:
6
+ // https://github.com/codemirror/CodeMirror/issues/3701#issuecomment-164904534
7
+ let syntaxHighlighter;
8
+ let canonicalLanguage = _ => '';
9
+ if (typeof window !== 'undefined') {
10
+ // eslint-disable-next-line global-require
11
+ syntaxHighlighter = require('@readme/syntax-highlighter').default;
12
+ // eslint-disable-next-line global-require
13
+ ({ canonical: canonicalLanguage } = require('@readme/syntax-highlighter'));
14
+ }
15
+
16
+ function CopyCode({ codeRef, rootClass = 'rdmd-code-copy', className = '' }) {
17
+ const copyClass = `${rootClass}_copied`;
18
+ const button = createRef<HTMLButtonElement>();
19
+
20
+ const copier = () => {
21
+ const code = codeRef.current.textContent;
22
+
23
+ if (copy(code)) {
24
+ const el = button.current;
25
+ el.classList.add(copyClass);
26
+
27
+ setTimeout(() => el.classList.remove(copyClass), 1500);
28
+ }
29
+ };
30
+
31
+ return <button ref={button} aria-label="Copy Code" className={`${rootClass} ${className}`} onClick={copier} />;
32
+ }
33
+
34
+ interface Props extends Omit<HTMLElement, 'lang'> {
35
+ copyButtons?: boolean;
36
+ lang?: string;
37
+ meta?: string;
38
+ theme?: string;
39
+ value?: string;
40
+ }
41
+
42
+ const Code = (props: Props) => {
43
+ const { children, copyButtons, lang, theme, value } = props;
44
+
45
+ const language = canonicalLanguage(lang);
46
+
47
+ const codeRef = createRef<HTMLElement>();
48
+
49
+ const codeOpts = {
50
+ inline: !lang,
51
+ tokenizeVariables: true,
52
+ dark: theme === 'dark',
53
+ };
54
+
55
+ const code = value ?? children?.[0] ?? children ?? '';
56
+ const highlightedCode = syntaxHighlighter && code ? syntaxHighlighter(code, language, codeOpts) : code;
57
+
58
+ return (
59
+ <>
60
+ {copyButtons && <CopyCode className="fa" codeRef={codeRef} />}
61
+ <code
62
+ ref={codeRef}
63
+ className={['rdmd-code', `lang-${language}`, `theme-${theme}`].join(' ')}
64
+ data-lang={language}
65
+ suppressHydrationWarning={true}
66
+ >
67
+ {highlightedCode}
68
+ </code>
69
+ </>
70
+ );
71
+ };
72
+
73
+ export default Code;
@@ -1,14 +1,13 @@
1
- const { uppercase } = require('@readme/syntax-highlighter');
2
- const PropTypes = require('prop-types');
3
- const React = require('react');
1
+ import { uppercase } from '@readme/syntax-highlighter';
2
+ import React from 'react';
4
3
 
5
4
  const CodeTabs = props => {
6
5
  const { children, theme } = props;
7
6
 
8
- function handleClick({ target }, index) {
7
+ function handleClick({ target }, index: number) {
9
8
  const $wrap = target.parentElement.parentElement;
10
9
  const $open = [].slice.call($wrap.querySelectorAll('.CodeTabs_active'));
11
- $open.forEach(el => el.classList.remove('CodeTabs_active'));
10
+ $open.forEach((el: Element) => el.classList.remove('CodeTabs_active'));
12
11
  $wrap.classList.remove('CodeTabs_initial');
13
12
 
14
13
  const codeblocks = $wrap.querySelectorAll('pre');
@@ -20,8 +19,9 @@ const CodeTabs = props => {
20
19
  return (
21
20
  <div className={`CodeTabs CodeTabs_initial theme-${theme}`}>
22
21
  <div className="CodeTabs-toolbar">
23
- {children.map(({ props: pre }, i) => {
24
- const { meta, lang } = pre.children[0].props;
22
+ {(Array.isArray(children) ? children : [children]).map((pre, i) => {
23
+ const { meta, lang } = pre.props.children.props;
24
+
25
25
  /* istanbul ignore next */
26
26
  return (
27
27
  <button key={i} onClick={e => handleClick(e, i)} type="button">
@@ -35,15 +35,4 @@ const CodeTabs = props => {
35
35
  );
36
36
  };
37
37
 
38
- CodeTabs.propTypes = {
39
- children: PropTypes.arrayOf(PropTypes.any).isRequired,
40
- theme: PropTypes.string,
41
- };
42
-
43
- function CreateCodeTabs({ theme }) {
44
- // eslint-disable-next-line react/display-name
45
- return props => <CodeTabs {...props} theme={theme} />;
46
- }
47
-
48
- module.exports = CreateCodeTabs;
49
- module.exports.CodeTabs = CodeTabs;
38
+ export default CodeTabs;
@@ -5,8 +5,5 @@ interface Props extends React.PropsWithChildren<React.HTMLAttributes<HTMLQuoteEl
5
5
  theme: string;
6
6
  heading?: React.ReactElement;
7
7
  }
8
- declare const Callout: {
9
- (props: Props): React.JSX.Element;
10
- sanitize(sanitizeSchema: any): any;
11
- };
8
+ declare const Callout: (props: Props) => React.JSX.Element;
12
9
  export default Callout;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ interface Props extends Omit<HTMLElement, 'lang'> {
3
+ copyButtons?: boolean;
4
+ lang?: string;
5
+ meta?: string;
6
+ theme?: string;
7
+ value?: string;
8
+ }
9
+ declare const Code: (props: Props) => React.JSX.Element;
10
+ export default Code;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const CodeTabs: (props: any) => React.JSX.Element;
3
+ export default CodeTabs;
@@ -0,0 +1,5 @@
1
+ export declare enum NodeTypes {
2
+ codeTabs = "code-tabs",
3
+ emoji = "emoji",
4
+ i = "i"
5
+ }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import React from 'react';
1
2
  import { RunOptions } from '@mdx-js/mdx';
2
3
  import * as Components from './components';
3
- import React from 'react';
4
4
  type RunOpts = Omit<RunOptions, 'Fragment'> & {
5
5
  components?: Record<string, () => React.ReactNode>;
6
6
  imports?: Record<string, unknown>;
@@ -21,6 +21,6 @@ export declare const reactTOC: (text: string, opts?: {}) => void;
21
21
  export declare const mdx: (tree: any, opts?: {}) => string;
22
22
  export declare const html: (text: string, opts?: {}) => void;
23
23
  export declare const mdast: any;
24
- export declare const hast: (text: string, opts?: {}) => void;
24
+ export declare const hast: (text: string, opts?: {}) => import("hast").Root;
25
25
  export declare const esast: (text: string, opts?: {}) => void;
26
26
  export declare const plain: (text: string, opts?: {}) => void;
@@ -0,0 +1,4 @@
1
+ export default class Owlmoji {
2
+ static kind: (name: string) => "gemoji" | "fontawesome" | "owlmoji";
3
+ static nameToEmoji: Record<string, string>;
4
+ }