@readme/markdown 6.75.0-beta.27 → 6.75.0-beta.29

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;
@@ -0,0 +1,31 @@
1
+ import React, { useContext } from 'react';
2
+ import Tooltip from '@tippyjs/react';
3
+ import GlossaryContext from '../../contexts/GlossaryTerms';
4
+ import type { GlossaryItem, GlossaryTerm } from '../../contexts/GlossaryTerms';
5
+
6
+ const GlossaryItem = ({ term, terms }: { term: string; terms: GlossaryTerm[] }) => {
7
+ const foundTerm = terms.find(i => term.toLowerCase() === i.term.toLowerCase());
8
+
9
+ if (!foundTerm) return <span>{term}</span>;
10
+
11
+ return (
12
+ <Tooltip
13
+ content={
14
+ <div className="GlossaryItem-tooltip-content">
15
+ <strong className="GlossaryItem-term">{foundTerm.term}</strong> - {foundTerm.definition}
16
+ </div>
17
+ }
18
+ offset={[-5, 5]}
19
+ placement="bottom-start"
20
+ >
21
+ <span className="GlossaryItem-trigger">{term}</span>
22
+ </Tooltip>
23
+ );
24
+ };
25
+
26
+ const GlossaryItemWithContext = props => {
27
+ const terms = useContext(GlossaryContext);
28
+ return terms ? <GlossaryItem {...props} terms={terms} /> : null;
29
+ };
30
+
31
+ export { GlossaryItem, GlossaryItemWithContext as default, GlossaryContext };
@@ -0,0 +1,111 @@
1
+ import * as React from 'react';
2
+
3
+ interface Props extends React.PropsWithChildren<React.HTMLAttributes<HTMLImageElement>> {
4
+ align: string;
5
+ alt: string;
6
+ border: boolean;
7
+ caption: string;
8
+ className: string;
9
+ height: string;
10
+ lazy: boolean;
11
+ src: string;
12
+ title: string;
13
+ width: string;
14
+ }
15
+
16
+ const Image = (props: Props) => {
17
+ const [lightbox, setLightbox] = React.useState(false);
18
+
19
+ const {
20
+ align = '',
21
+ alt = '',
22
+ border = false,
23
+ caption,
24
+ className = '',
25
+ height = 'auto',
26
+ lazy,
27
+ src = '',
28
+ title = '',
29
+ width = 'auto',
30
+ } = props;
31
+
32
+ if (className === 'emoji') {
33
+ return <img src={src} width={width} height={height} title={title} alt={alt} loading={lazy ? 'lazy' : 'eager'} />;
34
+ }
35
+
36
+ const handleKeyDown = ({ key, metaKey: cmd }: React.KeyboardEvent<HTMLImageElement>) => {
37
+ const cmdKey = cmd ? 'cmd+' : '';
38
+ key = `${cmdKey}${key.toLowerCase()}`;
39
+
40
+ switch (key) {
41
+ case 'cmd+.':
42
+ case 'escape':
43
+ // CLOSE
44
+ setLightbox(false);
45
+ break;
46
+ case ' ':
47
+ case 'enter':
48
+ // OPEN
49
+ if (!lightbox) setLightbox(true);
50
+ default:
51
+ }
52
+ };
53
+
54
+ const toggle = () => {
55
+ if (className === 'emoji') return;
56
+ setLightbox(!lightbox);
57
+ };
58
+
59
+ if (caption) {
60
+ return (
61
+ <figure>
62
+ <span
63
+ aria-label={alt}
64
+ className={`img lightbox ${lightbox ? 'open' : 'closed'}`}
65
+ onClick={toggle}
66
+ onKeyDown={handleKeyDown}
67
+ role={'button'}
68
+ tabIndex={0}
69
+ >
70
+ <span className="lightbox-inner">
71
+ <img
72
+ src={src}
73
+ width={width}
74
+ height={height}
75
+ title={title}
76
+ className={`img img-align-center ${border ? 'border' : ''}`}
77
+ alt={alt}
78
+ loading={lazy ? 'lazy' : 'eager'}
79
+ />
80
+ </span>
81
+ </span>
82
+ <figcaption>{caption}</figcaption>
83
+ </figure>
84
+ );
85
+ }
86
+
87
+ return (
88
+ <span
89
+ aria-label={alt}
90
+ className={`img lightbox ${lightbox ? 'open' : 'closed'}`}
91
+ onClick={toggle}
92
+ onKeyDown={handleKeyDown}
93
+ role={'button'}
94
+ tabIndex={0}
95
+ >
96
+ <span className="lightbox-inner">
97
+ <img
98
+ src={src}
99
+ width={width}
100
+ height={height}
101
+ title={title}
102
+ className={`img img-align-${align} ${border ? 'border' : ''}`}
103
+ alt={alt}
104
+ loading={lazy ? 'lazy' : 'eager'}
105
+ />
106
+ </span>
107
+ </span>
108
+ );
109
+ };
110
+
111
+ export default Image;
@@ -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,9 @@
1
+ import React from 'react';
2
+ import GlossaryContext from '../../contexts/GlossaryTerms';
3
+ import type { GlossaryItem, GlossaryTerm } from '../../contexts/GlossaryTerms';
4
+ declare const GlossaryItem: ({ term, terms }: {
5
+ term: string;
6
+ terms: GlossaryTerm[];
7
+ }) => React.JSX.Element;
8
+ declare const GlossaryItemWithContext: (props: any) => React.JSX.Element;
9
+ export { GlossaryItem, GlossaryItemWithContext as default, GlossaryContext };
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ interface Props extends React.PropsWithChildren<React.HTMLAttributes<HTMLImageElement>> {
3
+ align: string;
4
+ alt: string;
5
+ border: boolean;
6
+ caption: string;
7
+ className: string;
8
+ height: string;
9
+ lazy: boolean;
10
+ src: string;
11
+ title: string;
12
+ width: string;
13
+ }
14
+ declare const Image: (props: Props) => React.JSX.Element;
15
+ export default Image;
@@ -0,0 +1,12 @@
1
+ export { default as Anchor } from './Anchor';
2
+ export { default as Callout } from './Callout';
3
+ export { default as Code } from './Code';
4
+ export { default as CodeTabs } from './CodeTabs';
5
+ export { default as Embed } from './Embed';
6
+ export { default as GlossaryItem } from './GlossaryItem';
7
+ export { default as HTMLBlock } from './HTMLBlock';
8
+ export { default as Heading } from './Heading';
9
+ export { default as Image } from './Image';
10
+ export { default as Style } from './Style';
11
+ export { default as Table } from './Table';
12
+ export { default as TableOfContents } from './TableOfContents';
@@ -0,0 +1,15 @@
1
+ import { ReactNode } from "react";
2
+ export type GlossaryTerm = {
3
+ term: string;
4
+ definition: string;
5
+ _id?: string;
6
+ };
7
+ export type GlossaryItem = {
8
+ term?: string;
9
+ terms: GlossaryTerm[];
10
+ };
11
+ declare const GlossaryContext: import("react").Context<GlossaryTerm[]>;
12
+ export default GlossaryContext;
13
+ export declare function Provider(Provider: any, arg1: {
14
+ value: GlossaryTerm[];
15
+ }): ReactNode;
@@ -0,0 +1,6 @@
1
+ export declare enum NodeTypes {
2
+ codeTabs = "code-tabs",
3
+ emoji = "emoji",
4
+ i = "i",
5
+ image = "image"
6
+ }
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>;
@@ -10,7 +10,7 @@ export declare const utils: {
10
10
  readonly options: any;
11
11
  BaseUrlContext: any;
12
12
  getHref: any;
13
- GlossaryContext: any;
13
+ GlossaryContext: React.Context<import("./contexts/GlossaryTerms").GlossaryTerm[]>;
14
14
  VariablesContext: any;
15
15
  calloutIcons: {};
16
16
  };
@@ -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
+ }