@readme/markdown 7.6.6 → 7.7.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.
- package/README.md +60 -79
- package/components/Code/index.tsx +7 -3
- package/components/Code/style.scss +6 -0
- package/components/CodeTabs/index.tsx +25 -2
- package/components/Image/style.scss +7 -4
- package/dist/10.js +22718 -0
- package/dist/10.node.js +22721 -0
- package/dist/11.js +1440 -0
- package/dist/11.node.js +1443 -0
- package/dist/120.js +19 -0
- package/dist/120.node.js +22 -0
- package/dist/134.js +19 -0
- package/dist/134.node.js +22 -0
- package/dist/150.js +1888 -0
- package/dist/150.node.js +1891 -0
- package/dist/17.js +1373 -0
- package/dist/17.node.js +1376 -0
- package/dist/246.js +1929 -0
- package/dist/246.node.js +1932 -0
- package/dist/351.js +2400 -0
- package/dist/351.node.js +2403 -0
- package/dist/366.js +1181 -0
- package/dist/366.node.js +1184 -0
- package/dist/403.js +2192 -0
- package/dist/403.node.js +2195 -0
- package/dist/429.js +11130 -0
- package/dist/429.node.js +11133 -0
- package/dist/485.js +514 -0
- package/dist/485.node.js +517 -0
- package/dist/488.js +55 -0
- package/dist/488.node.js +58 -0
- package/dist/489.js +18472 -0
- package/dist/489.node.js +18475 -0
- package/dist/510.js +246 -0
- package/dist/510.node.js +249 -0
- package/dist/52.js +808 -0
- package/dist/52.node.js +811 -0
- package/dist/550.node.js +1456 -0
- package/dist/551.js +2722 -0
- package/dist/551.node.js +2725 -0
- package/dist/617.js +19 -0
- package/dist/617.node.js +22 -0
- package/dist/687.js +3671 -0
- package/dist/687.node.js +3674 -0
- package/dist/745.js +7504 -0
- package/dist/745.node.js +7507 -0
- package/dist/775.js +1900 -0
- package/dist/775.node.js +1903 -0
- package/dist/786.js +31378 -0
- package/dist/786.node.js +31381 -0
- package/dist/788.js +1021 -0
- package/dist/788.node.js +1024 -0
- package/dist/81.js +382 -0
- package/dist/81.node.js +385 -0
- package/dist/849.js +2586 -0
- package/dist/849.node.js +2589 -0
- package/dist/863.js +19 -0
- package/dist/863.node.js +22 -0
- package/dist/867.js +1414 -0
- package/dist/867.node.js +1417 -0
- package/dist/871.js +1533 -0
- package/dist/881.js +1276 -0
- package/dist/881.node.js +1279 -0
- package/dist/885.js +48 -0
- package/dist/885.node.js +51 -0
- package/dist/896.js +1613 -0
- package/dist/896.node.js +1616 -0
- package/dist/906.js +1815 -0
- package/dist/906.node.js +1818 -0
- package/dist/91.js +19 -0
- package/dist/91.node.js +22 -0
- package/dist/940.js +3359 -0
- package/dist/940.node.js +3362 -0
- package/dist/952.js +243 -0
- package/dist/952.node.js +246 -0
- package/dist/995.js +5734 -0
- package/dist/995.node.js +5737 -0
- package/dist/components/Code/index.d.ts +1 -1
- package/dist/lib/ast-processor.d.ts +3 -1
- package/dist/lib/compile.d.ts +2 -1
- package/dist/main.css +1 -1
- package/dist/main.js +94787 -73737
- package/dist/main.node.js +103724 -82783
- package/dist/processor/transform/code-tabs.d.ts +3 -1
- package/dist/processor/transform/index.d.ts +12 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,129 +1,110 @@
|
|
|
1
|
-
#
|
|
1
|
+
# <img align="right" width="26%" src="https://owlbertsio-resized.s3.amazonaws.com/Reading.psd.full.png"> `@readme/markdown`
|
|
2
2
|
|
|
3
|
-
<img align=
|
|
3
|
+
<img align=right src=https://github.com/readmeio/markdown/workflows/CI/badge.svg alt="RDMD CI Status"> ReadMe's MDX rendering engine and custom component collection.
|
|
4
|
+
<br/> *(Use ReadMe? [Learn more about our upcoming move to MDX](https://docs.readme.com/rdmd/page/mdx-engine)!)*
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
## Getting Started
|
|
7
|
+
|
|
8
|
+
To use the engine, install it from NPM:
|
|
6
9
|
|
|
7
10
|
```
|
|
8
11
|
npm install --save @readme/markdown
|
|
9
12
|
```
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
Then [`compile`](#compile) and [`run`](#run) your MDX:
|
|
12
15
|
|
|
13
16
|
```jsx
|
|
14
|
-
import
|
|
15
|
-
import rmdx from '@readme/markdown';
|
|
17
|
+
import RMDX from '@readme/markdown';
|
|
16
18
|
|
|
17
|
-
export default ({ body }) =>
|
|
19
|
+
export default ({ body }) => (
|
|
20
|
+
<div className="markdown-body">
|
|
21
|
+
{RMDX.run(RMDX.compile(body))}
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
18
24
|
```
|
|
19
25
|
|
|
20
|
-
|
|
26
|
+
## API
|
|
21
27
|
|
|
22
|
-
|
|
28
|
+
### `compile`
|
|
23
29
|
|
|
24
|
-
Compiles MDX to JS. Essentially a wrapper around [`mdx.compile`](https://mdxjs.com/packages/mdx/#compilefile-options).
|
|
30
|
+
Compiles MDX to JS. Essentially a wrapper around [`mdx.compile`](https://mdxjs.com/packages/mdx/#compilefile-options). Used before calling [`run`](#run); it has been left as a seperate method for potential caching opportunities.
|
|
25
31
|
|
|
26
|
-
|
|
32
|
+
#### Parameters
|
|
27
33
|
|
|
28
|
-
-
|
|
29
|
-
-
|
|
34
|
+
- **`string`** (`string`)—an MDX document
|
|
35
|
+
- **`opts`** ([`CompileOpts`](#compileopts), optional)—a configuration object
|
|
30
36
|
|
|
31
|
-
|
|
37
|
+
#### Returns
|
|
32
38
|
|
|
33
|
-
compiled code
|
|
39
|
+
A string of compiled Javascript module code.
|
|
34
40
|
|
|
35
|
-
|
|
41
|
+
### `run`
|
|
36
42
|
|
|
37
43
|
> [!CAUTION]
|
|
38
|
-
>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
A module ([`RMDXModule`](#rmdxmodule)) of renderable components
|
|
48
|
-
|
|
49
|
-
#### `mdx`
|
|
50
|
-
|
|
51
|
-
Compiles an ast to mdx.
|
|
52
|
-
|
|
53
|
-
###### Parameters
|
|
54
|
-
|
|
55
|
-
Extends [`remark-stringify` options](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options).
|
|
56
|
-
|
|
57
|
-
###### Returns
|
|
44
|
+
> This is essentially a wrapper around [`mdx.run`](https://mdxjs.com/packages/mdx/#runcode-options) and **it will `eval` the compiled MDX**. Make sure you only call `run` on safe syntax from a trusted author!
|
|
45
|
+
>
|
|
46
|
+
> #### Parameters
|
|
47
|
+
> - **`string`** (`string`)—a compiled mdx document
|
|
48
|
+
> - **`opts`** (`RunOpts`, optional)—configuration
|
|
49
|
+
>
|
|
50
|
+
> #### Returns
|
|
51
|
+
> An [`RMDXModule`](#rmdxmodule) of renderable components.
|
|
58
52
|
|
|
59
|
-
|
|
53
|
+
### `mdx`
|
|
60
54
|
|
|
61
|
-
|
|
55
|
+
Compiles an AST to a string of MDX syntax.
|
|
62
56
|
|
|
63
|
-
|
|
57
|
+
#### Parameters
|
|
64
58
|
|
|
65
|
-
|
|
59
|
+
- **`tree`** (`object`)—an abstract syntax tree
|
|
60
|
+
- **`opts`** ([`Options`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options "`remark-stringify` Options type"))—`remark-stringify` configuration.
|
|
66
61
|
|
|
67
|
-
|
|
62
|
+
#### Returns
|
|
68
63
|
|
|
69
|
-
|
|
64
|
+
An MDX string.
|
|
70
65
|
|
|
71
|
-
|
|
66
|
+
### Other Methods
|
|
72
67
|
|
|
73
|
-
|
|
68
|
+
- **`mdast`**: parse MDX syntax to MDAST.
|
|
69
|
+
- **`hast`**: parse MDX syntax to HAST.
|
|
70
|
+
- **`plain`**: parse MDX to a plaintext string with all Markdown syntax removed. (This *does not* `eval` the doc.)
|
|
71
|
+
- **`tags`**: get a list of tag names from the doc. (This *does not* `eval` the doc.)
|
|
72
|
+
- **`utils`**: additional defaults, helper methods, components, and so on.
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
#### `utils`
|
|
78
|
-
|
|
79
|
-
Additional defaults, helpers, components, etc.
|
|
74
|
+
## Types
|
|
80
75
|
|
|
81
76
|
### `CompileOpts`
|
|
82
77
|
|
|
83
78
|
Extends [`CompileOptions`](https://mdxjs.com/packages/mdx/#compileoptions)
|
|
84
79
|
|
|
85
|
-
|
|
80
|
+
##### Additional Properties
|
|
86
81
|
|
|
87
|
-
-
|
|
88
|
-
-
|
|
89
|
-
-
|
|
90
|
-
-
|
|
82
|
+
- **`lazyImages`** (`boolean`, optional)—load images lazily
|
|
83
|
+
- **`safeMode`** (`boolean`, optional)—extract script tags from `HTMLBlock`s
|
|
84
|
+
- **`components`** (`Record<string, string>`, optional)—an object of tag names to mdx.
|
|
85
|
+
- **`copyButtons`** (`Boolean`, optional) — add a copy button to code blocks
|
|
91
86
|
|
|
92
87
|
### `RunOpts`
|
|
93
88
|
|
|
94
89
|
Extends [`RunOptions`](https://mdxjs.com/packages/mdx/#runoptions)
|
|
95
90
|
|
|
96
|
-
|
|
91
|
+
##### Additional Properties
|
|
97
92
|
|
|
98
|
-
-
|
|
99
|
-
-
|
|
100
|
-
-
|
|
101
|
-
-
|
|
93
|
+
- **`components`** (`Record<string, MDXModule>`, optional)—a set of custom MDX components
|
|
94
|
+
- **`imports`** (`Record<string, unknown>`, optional)—an set of modules to import globally
|
|
95
|
+
- **`terms`** (`GlossaryTerm[]`, optional)
|
|
96
|
+
- **`variables`** (`Variables`, optional)—an object containing [user variables](https://github.com/readmeio/variable)
|
|
102
97
|
|
|
103
98
|
### `RMDXModule`
|
|
104
99
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
- `default` (`() => MDXContent`) -- the MDX douments default export
|
|
108
|
-
- `toc` (`HastHeading[]`) -- a list of headings in the document
|
|
109
|
-
- `Toc` (`() => MDCContent`) -- a table of contents component
|
|
100
|
+
##### Properties
|
|
110
101
|
|
|
111
|
-
|
|
102
|
+
- **`default`** (`() => MDXContent`)—the MDX douments default export
|
|
103
|
+
- **`toc`** (`HastHeading[]`)—a list of headings in the document
|
|
104
|
+
- **`Toc`** (`() => MDCContent`)—a table of contents component
|
|
112
105
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
## Local Development
|
|
106
|
+
## Local Development and Testing
|
|
116
107
|
|
|
117
108
|
To make changes to the RDMD engine locally, run the local development server. Clone the repo, `cd` in to it, `npm install`, and `npm run start`!
|
|
118
109
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
Running the browser tests requires `docker`. Follow the docker [install instructions for mac](https://docs.docker.com/docker-for-mac/install/). You may want to increase the [memory usage](https://docs.docker.com/docker-for-mac/#resources). If you have not already, you'll need to create an account for `docker hub` and [sign-in locally](https://docs.docker.com/docker-for-mac/#docker-hub).
|
|
122
|
-
|
|
123
|
-
### Running visual regression tests
|
|
124
|
-
|
|
125
|
-
If you make changes to the docs or how the markdown is rendered, you may need to update the visual regression snapshots. You can run the visual regression tests in a docker container with:
|
|
126
|
-
|
|
127
|
-
```
|
|
128
|
-
make updateSnapshot
|
|
129
|
-
```
|
|
110
|
+
If you make changes to the docs or how the markdown is rendered, you may need to update the visual regression snapshots by running `make updateSnapshot`. Running these browser tests requires `docker`. Follow the docker [install instructions for mac](https://docs.docker.com/docker-for-mac/install/). You may want to increase the [memory usage](https://docs.docker.com/docker-for-mac/#resources). If you have not already, you'll need to create an account for `docker hub` and [sign-in locally](https://docs.docker.com/docker-for-mac/#docker-hub).
|
|
@@ -16,20 +16,20 @@ if (typeof window !== 'undefined') {
|
|
|
16
16
|
|
|
17
17
|
function CopyCode({ codeRef, rootClass = 'rdmd-code-copy', className = '' }) {
|
|
18
18
|
const copyClass = `${rootClass}_copied`;
|
|
19
|
-
const
|
|
19
|
+
const buttonRef = createRef<HTMLButtonElement>();
|
|
20
20
|
|
|
21
21
|
const copier = () => {
|
|
22
22
|
const code = codeRef.current.textContent;
|
|
23
23
|
|
|
24
24
|
if (copy(code)) {
|
|
25
|
-
const el =
|
|
25
|
+
const el = buttonRef.current;
|
|
26
26
|
el.classList.add(copyClass);
|
|
27
27
|
|
|
28
28
|
setTimeout(() => el.classList.remove(copyClass), 1500);
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
return <button ref={
|
|
32
|
+
return <button ref={buttonRef} aria-label="Copy Code" className={`${rootClass} ${className}`} onClick={copier} />;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
interface CodeProps {
|
|
@@ -57,6 +57,10 @@ const Code = (props: CodeProps) => {
|
|
|
57
57
|
const code = value ?? (Array.isArray(children) ? children[0] : children) ?? '';
|
|
58
58
|
const highlightedCode = syntaxHighlighter && code ? syntaxHighlighter(code, language, codeOpts, { mdx: true }) : code;
|
|
59
59
|
|
|
60
|
+
if (language === 'mermaid') {
|
|
61
|
+
return code;
|
|
62
|
+
}
|
|
63
|
+
|
|
60
64
|
return (
|
|
61
65
|
<>
|
|
62
66
|
{copyButtons && <CopyCode className="fa" codeRef={codeRef} />}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { uppercase } from '@readme/syntax-highlighter';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
|
+
import mermaid from 'mermaid';
|
|
3
4
|
|
|
4
5
|
const CodeTabs = props => {
|
|
5
6
|
const { children, theme } = props;
|
|
6
7
|
|
|
8
|
+
// set Mermaid theme
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
mermaid.initialize({
|
|
11
|
+
theme: theme === 'dark' ? 'dark' : 'default',
|
|
12
|
+
});
|
|
13
|
+
}, [theme])
|
|
14
|
+
|
|
7
15
|
function handleClick({ target }, index: number) {
|
|
8
16
|
const $wrap = target.parentElement.parentElement;
|
|
9
17
|
const $open = [].slice.call($wrap.querySelectorAll('.CodeTabs_active'));
|
|
@@ -14,6 +22,21 @@ const CodeTabs = props => {
|
|
|
14
22
|
codeblocks[index].classList.add('CodeTabs_active');
|
|
15
23
|
|
|
16
24
|
target.classList.add('CodeTabs_active');
|
|
25
|
+
|
|
26
|
+
if (target.value === 'mermaid') {
|
|
27
|
+
const $openMermaid = [].slice.call($wrap.querySelectorAll('.mermaid'));
|
|
28
|
+
$openMermaid.forEach((el: Element) => el.classList.remove('mermaid'));
|
|
29
|
+
codeblocks[index].classList.add('mermaid');
|
|
30
|
+
mermaid.contentLoaded();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// render single Mermaid diagram
|
|
35
|
+
if (!Array.isArray(children) && children.props?.children.props.lang === 'mermaid') {
|
|
36
|
+
const value = children.props.children.props.value;
|
|
37
|
+
return (
|
|
38
|
+
<pre className="mermaid mermaid_single">{value}</pre>
|
|
39
|
+
)
|
|
17
40
|
}
|
|
18
41
|
|
|
19
42
|
return (
|
|
@@ -24,7 +47,7 @@ const CodeTabs = props => {
|
|
|
24
47
|
|
|
25
48
|
/* istanbul ignore next */
|
|
26
49
|
return (
|
|
27
|
-
<button key={i} onClick={e => handleClick(e, i)} type="button">
|
|
50
|
+
<button key={i} onClick={e => handleClick(e, i)} type="button" value={lang}>
|
|
28
51
|
{meta || `${!lang ? 'Text' : uppercase(lang)}`}
|
|
29
52
|
</button>
|
|
30
53
|
);
|
|
@@ -28,15 +28,19 @@
|
|
|
28
28
|
outline: none !important;
|
|
29
29
|
vertical-align: middle;
|
|
30
30
|
|
|
31
|
+
&.img-align-right,
|
|
31
32
|
&[align='right'],
|
|
32
33
|
&[alt~='align-right'] {
|
|
33
34
|
@extend %img-align-right;
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
&.img-align-left,
|
|
36
38
|
&[align='left'],
|
|
37
39
|
&[alt~='align-left'] {
|
|
38
40
|
@extend %img-align-left;
|
|
41
|
+
|
|
39
42
|
}
|
|
43
|
+
&.img-align-center,
|
|
40
44
|
&[align='middle'], // hack to fix Firefox; see: https://stackoverflow.com/a/45901819/1341949
|
|
41
45
|
&[align='center'],
|
|
42
46
|
&[alt~='align-center'] {
|
|
@@ -65,8 +69,10 @@
|
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
|
|
72
|
+
> .img,
|
|
68
73
|
> img,
|
|
69
74
|
figure > img {
|
|
75
|
+
display: block;
|
|
70
76
|
@extend %img-align-center;
|
|
71
77
|
}
|
|
72
78
|
|
|
@@ -97,16 +103,13 @@
|
|
|
97
103
|
content: '\f00d';
|
|
98
104
|
cursor: pointer;
|
|
99
105
|
display: inline-block;
|
|
100
|
-
font:
|
|
106
|
+
font-family: var(--fa-style-family, 'Font Awesome 6 Pro');
|
|
101
107
|
font-size: inherit;
|
|
102
|
-
-webkit-font-smoothing: antialiased;
|
|
103
|
-
-moz-osx-font-smoothing: grayscale;
|
|
104
108
|
opacity: 1;
|
|
105
109
|
position: fixed;
|
|
106
110
|
right: 1em;
|
|
107
111
|
text-rendering: auto;
|
|
108
112
|
top: 1em;
|
|
109
|
-
transform: translate(0, 0);
|
|
110
113
|
transform: scale(1.5);
|
|
111
114
|
transition: 0.3s 0.3s ease-in;
|
|
112
115
|
}
|