@readme/markdown 6.75.0-beta.34 → 6.75.0-beta.36
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/Anchor.jsx +14 -25
- package/components/Callout/index.tsx +8 -8
- package/components/Glossary/index.tsx +37 -0
- package/components/Glossary/style.scss +69 -0
- package/components/index.ts +1 -1
- package/dist/components/Glossary/index.d.ts +10 -0
- package/dist/components/index.d.ts +1 -1
- package/dist/contexts/GlossaryTerms.d.ts +0 -8
- package/dist/contexts/index.d.ts +5 -0
- package/dist/index.d.ts +15 -5
- package/dist/main.js +254 -209
- package/dist/main.node.js +191 -166
- package/dist/processor/compile/callout.d.ts +3 -0
- package/package.json +1 -1
- package/styles/components.scss +1 -1
- package/components/GlossaryItem/index.tsx +0 -31
- package/components/GlossaryItem/style.scss +0 -60
- package/dist/components/GlossaryItem/index.d.ts +0 -9
package/components/Anchor.jsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { string, node } from 'prop-types';
|
|
2
|
+
import React from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import BaseUrlContext from '../contexts/BaseUrl';
|
|
5
5
|
|
|
6
6
|
// Nabbed from here:
|
|
7
7
|
// https://github.com/readmeio/api-explorer/blob/0dedafcf71102feedaa4145040d3f57d79d95752/packages/api-explorer/src/lib/markdown/renderer.js#L52
|
|
8
|
-
function getHref(href, baseUrl) {
|
|
8
|
+
export function getHref(href, baseUrl) {
|
|
9
9
|
const [path, hash] = href.split('#');
|
|
10
10
|
const hashStr = hash ? `#${hash}` : '';
|
|
11
11
|
|
|
@@ -49,7 +49,9 @@ function docLink(href) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
function Anchor(props) {
|
|
52
|
-
const {
|
|
52
|
+
const { children, href, target, title, ...attrs } = props;
|
|
53
|
+
const baseUrl = useContext(BaseUrlContext);
|
|
54
|
+
|
|
53
55
|
return (
|
|
54
56
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
55
57
|
<a {...attrs} href={getHref(href, baseUrl)} target={target} title={title} {...docLink(href)}>
|
|
@@ -59,12 +61,12 @@ function Anchor(props) {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
Anchor.propTypes = {
|
|
62
|
-
baseUrl:
|
|
63
|
-
children:
|
|
64
|
-
download:
|
|
65
|
-
href:
|
|
66
|
-
target:
|
|
67
|
-
title:
|
|
64
|
+
baseUrl: string,
|
|
65
|
+
children: node.isRequired,
|
|
66
|
+
download: string,
|
|
67
|
+
href: string,
|
|
68
|
+
target: string,
|
|
69
|
+
title: string,
|
|
68
70
|
};
|
|
69
71
|
|
|
70
72
|
Anchor.defaultProps = {
|
|
@@ -74,17 +76,4 @@ Anchor.defaultProps = {
|
|
|
74
76
|
title: '',
|
|
75
77
|
};
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
<BaseUrlContext.Consumer>{baseUrl => <Anchor baseUrl={baseUrl} {...props} />}</BaseUrlContext.Consumer>
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
AnchorWithContext.sanitize = sanitizeSchema => {
|
|
82
|
-
// This is for our custom link formats
|
|
83
|
-
sanitizeSchema.protocols.href.push('doc', 'target', 'ref', 'blog', 'changelog', 'page');
|
|
84
|
-
|
|
85
|
-
return sanitizeSchema;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
module.exports = AnchorWithContext;
|
|
89
|
-
|
|
90
|
-
AnchorWithContext.getHref = getHref;
|
|
79
|
+
export default Anchor;
|
|
@@ -23,20 +23,20 @@ const themes: Record<string, string> = {
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const Callout = (props: Props) => {
|
|
26
|
-
const { attributes, children, icon
|
|
26
|
+
const { attributes, children, icon } = props;
|
|
27
27
|
|
|
28
28
|
let theme = props.theme || themes[icon] || 'default';
|
|
29
|
+
const [heading, ...body] = Array.isArray(children) ? children : [children];
|
|
30
|
+
const empty = !heading.props.children;
|
|
29
31
|
|
|
30
32
|
return (
|
|
31
33
|
// @ts-ignore
|
|
32
34
|
<blockquote {...attributes} className={`callout callout_${theme}`} theme={icon}>
|
|
33
|
-
{heading
|
|
34
|
-
<
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
)}
|
|
39
|
-
{children}
|
|
35
|
+
<h3 className={`callout-heading${empty ? ' empty' : ''}`}>
|
|
36
|
+
<span className="callout-icon">{icon}</span>
|
|
37
|
+
{!empty && heading}
|
|
38
|
+
</h3>
|
|
39
|
+
{body}
|
|
40
40
|
</blockquote>
|
|
41
41
|
);
|
|
42
42
|
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import Tooltip from '@tippyjs/react';
|
|
3
|
+
import GlossaryContext from '../../contexts/GlossaryTerms';
|
|
4
|
+
import type { GlossaryTerm } from '../../contexts/GlossaryTerms';
|
|
5
|
+
|
|
6
|
+
interface Props extends React.PropsWithChildren {
|
|
7
|
+
term?: string;
|
|
8
|
+
terms: GlossaryTerm[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const Glossary = ({ children, term: termProp, terms }: Props) => {
|
|
12
|
+
const term = (Array.isArray(children) ? children[0] : children) || termProp;
|
|
13
|
+
const foundTerm = terms.find(i => term.toLowerCase() === i?.term?.toLowerCase());
|
|
14
|
+
|
|
15
|
+
if (!foundTerm) return <span>{term}</span>;
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<Tooltip
|
|
19
|
+
content={
|
|
20
|
+
<div className="Glossary-tooltip-content">
|
|
21
|
+
<strong className="Glossary-term">{foundTerm.term}</strong> - {foundTerm.definition}
|
|
22
|
+
</div>
|
|
23
|
+
}
|
|
24
|
+
offset={[-5, 5]}
|
|
25
|
+
placement="bottom-start"
|
|
26
|
+
>
|
|
27
|
+
<span className="Glossary-trigger">{term}</span>
|
|
28
|
+
</Tooltip>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const GlossaryWithContext = props => {
|
|
33
|
+
const terms = useContext(GlossaryContext);
|
|
34
|
+
return terms ? <Glossary {...props} terms={terms} /> : <span>{props.term}</span>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { Glossary, GlossaryWithContext as default, GlossaryContext };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
.Glossary {
|
|
2
|
+
&-trigger {
|
|
3
|
+
border-bottom: 1px solid #737c83;
|
|
4
|
+
border-style: dotted;
|
|
5
|
+
border-top: none;
|
|
6
|
+
border-left: none;
|
|
7
|
+
border-right: none;
|
|
8
|
+
cursor: pointer;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
&-tooltip-content {
|
|
12
|
+
--Glossary-bg: var(--color-bg-page, var(--white));
|
|
13
|
+
--Glossary-color: var(--color-text-default, var(--gray20));
|
|
14
|
+
--Glossary-shadow: var(
|
|
15
|
+
--box-shadow-menu-light,
|
|
16
|
+
0 5px 10px rgba(0, 0, 0, 0.05),
|
|
17
|
+
0 2px 6px rgba(0, 0, 0, 0.025),
|
|
18
|
+
0 1px 3px rgba(0, 0, 0, 0.025)
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
/* what the dark-mode mixin does in the readme project */
|
|
22
|
+
[data-color-mode='dark'] & {
|
|
23
|
+
--Glossary-bg: var(--gray15);
|
|
24
|
+
--Glossary-color: var(--color-text-default, var(--white));
|
|
25
|
+
--Glossary-shadow: var(
|
|
26
|
+
--box-shadow-menu-dark,
|
|
27
|
+
0 1px 3px rgba(0, 0, 0, 0.025),
|
|
28
|
+
0 2px 6px rgba(0, 0, 0, 0.025),
|
|
29
|
+
0 5px 10px rgba(0, 0, 0, 0.05)
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@media (prefers-color-scheme: dark) {
|
|
34
|
+
[data-color-mode='auto'] & {
|
|
35
|
+
--Glossary-bg: var(--Tooltip-bg, var(--gray0));
|
|
36
|
+
--Glossary-color: var(--color-text-default, var(--white));
|
|
37
|
+
--Glossary-shadow: var(
|
|
38
|
+
--box-shadow-menu-dark,
|
|
39
|
+
0 1px 3px rgba(0, 0, 0, 0.025),
|
|
40
|
+
0 2px 6px rgba(0, 0, 0, 0.025),
|
|
41
|
+
0 5px 10px rgba(0, 0, 0, 0.05)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
background-color: var(--Glossary-bg);
|
|
47
|
+
border: 1px solid #{var(--color-border-default, rgba(black, 0.1))};
|
|
48
|
+
border-radius: var(--border-radius);
|
|
49
|
+
box-shadow: var(--Glossary-shadow);
|
|
50
|
+
color: var(--Glossary-color);
|
|
51
|
+
font-size: 15px;
|
|
52
|
+
font-weight: 400;
|
|
53
|
+
line-height: 1.5;
|
|
54
|
+
padding: 15px;
|
|
55
|
+
text-align: left;
|
|
56
|
+
width: 350px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
&-term {
|
|
60
|
+
font-style: italic;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.tippy-box {
|
|
65
|
+
// needed for tippy's default animation
|
|
66
|
+
&[data-animation='fade'][data-state='hidden'] {
|
|
67
|
+
opacity: 0;
|
|
68
|
+
}
|
|
69
|
+
}
|
package/components/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { default as Callout } from './Callout';
|
|
|
3
3
|
export { default as Code } from './Code';
|
|
4
4
|
export { default as CodeTabs } from './CodeTabs';
|
|
5
5
|
export { default as Embed } from './Embed';
|
|
6
|
-
export { default as
|
|
6
|
+
export { default as Glossary } from './Glossary';
|
|
7
7
|
export { default as HTMLBlock } from './HTMLBlock';
|
|
8
8
|
export { default as Heading } from './Heading';
|
|
9
9
|
export { default as Image } from './Image';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import GlossaryContext from '../../contexts/GlossaryTerms';
|
|
3
|
+
import type { GlossaryTerm } from '../../contexts/GlossaryTerms';
|
|
4
|
+
interface Props extends React.PropsWithChildren {
|
|
5
|
+
term?: string;
|
|
6
|
+
terms: GlossaryTerm[];
|
|
7
|
+
}
|
|
8
|
+
declare const Glossary: ({ children, term: termProp, terms }: Props) => React.JSX.Element;
|
|
9
|
+
declare const GlossaryWithContext: (props: any) => React.JSX.Element;
|
|
10
|
+
export { Glossary, GlossaryWithContext as default, GlossaryContext };
|
|
@@ -3,7 +3,7 @@ export { default as Callout } from './Callout';
|
|
|
3
3
|
export { default as Code } from './Code';
|
|
4
4
|
export { default as CodeTabs } from './CodeTabs';
|
|
5
5
|
export { default as Embed } from './Embed';
|
|
6
|
-
export { default as
|
|
6
|
+
export { default as Glossary } from './Glossary';
|
|
7
7
|
export { default as HTMLBlock } from './HTMLBlock';
|
|
8
8
|
export { default as Heading } from './Heading';
|
|
9
9
|
export { default as Image } from './Image';
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
1
|
export type GlossaryTerm = {
|
|
3
2
|
term: string;
|
|
4
3
|
definition: string;
|
|
5
4
|
_id?: string;
|
|
6
5
|
};
|
|
7
|
-
export type GlossaryItem = {
|
|
8
|
-
term?: string;
|
|
9
|
-
terms: GlossaryTerm[];
|
|
10
|
-
};
|
|
11
6
|
declare const GlossaryContext: import("react").Context<GlossaryTerm[]>;
|
|
12
7
|
export default GlossaryContext;
|
|
13
|
-
export declare function Provider(Provider: any, arg1: {
|
|
14
|
-
value: GlossaryTerm[];
|
|
15
|
-
}): ReactNode;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { RunOpts } from '../index';
|
|
3
|
+
type Props = React.PropsWithChildren & Pick<RunOpts, 'baseUrl' | 'terms' | 'variables'>;
|
|
4
|
+
declare const Contexts: ({ children, terms, variables, baseUrl }: Props) => React.ReactNode;
|
|
5
|
+
export default Contexts;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { RunOptions } from '@mdx-js/mdx';
|
|
3
3
|
import * as Components from './components';
|
|
4
|
+
import { GlossaryTerm } from './contexts/GlossaryTerms';
|
|
4
5
|
type ComponentOpts = Record<string, (props: any) => React.ReactNode>;
|
|
5
|
-
|
|
6
|
+
interface Variables {
|
|
7
|
+
user: {
|
|
8
|
+
keys: string[];
|
|
9
|
+
};
|
|
10
|
+
defaults: {
|
|
11
|
+
name: string;
|
|
12
|
+
default: string;
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
15
|
+
export type RunOpts = Omit<RunOptions, 'Fragment'> & {
|
|
6
16
|
components?: ComponentOpts;
|
|
7
17
|
imports?: Record<string, unknown>;
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
terms?: GlossaryTerm[];
|
|
20
|
+
variables?: Variables;
|
|
8
21
|
};
|
|
9
22
|
export { Components };
|
|
10
23
|
export declare const utils: {
|
|
11
24
|
readonly options: any;
|
|
12
|
-
BaseUrlContext: any;
|
|
13
25
|
getHref: any;
|
|
14
|
-
GlossaryContext: React.Context<import("./contexts/GlossaryTerms").GlossaryTerm[]>;
|
|
15
|
-
VariablesContext: any;
|
|
16
26
|
calloutIcons: {};
|
|
17
27
|
};
|
|
18
28
|
export declare const reactProcessor: (opts?: {}) => import("unified").Processor<import("mdast").Root, import("estree").Program, import("estree").Program, import("estree").Program, string>;
|
|
19
29
|
export declare const compile: (text: string, opts?: {}) => string;
|
|
20
|
-
export declare const run: (code: string, _opts?: RunOpts) => Promise<
|
|
30
|
+
export declare const run: (code: string, _opts?: RunOpts) => Promise<() => React.JSX.Element>;
|
|
21
31
|
export declare const reactTOC: (text: string, opts?: {}) => void;
|
|
22
32
|
export declare const mdx: (tree: any, opts?: {}) => string;
|
|
23
33
|
export declare const html: (text: string, opts?: {}) => void;
|