@readme/markdown 6.75.0-beta.49 → 6.75.0-beta.51
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 +81 -23
- package/dist/index.d.ts +2 -5
- package/dist/lib/compile.d.ts +2 -3
- package/dist/lib/hast.d.ts +5 -0
- package/dist/lib/index.d.ts +4 -1
- package/dist/lib/mdast.d.ts +2 -0
- package/dist/lib/plain.d.ts +3 -0
- package/dist/lib/run.d.ts +5 -5
- package/dist/main.js +53424 -52806
- package/dist/main.node.js +65387 -64769
- package/dist/processor/plugin/toc.d.ts +9 -0
- package/dist/processor/transform/index.d.ts +2 -2
- package/dist/processor/transform/inject-components.d.ts +7 -0
- package/package.json +4 -2
- package/dist/processor/transform/rehype-toc.d.ts +0 -8
package/README.md
CHANGED
|
@@ -10,42 +10,100 @@ npm install --save @readme/markdown
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
By default, the updated markdown package exports a function which takes a string of [ReadMe-flavored markdown](https://docs.readme.com/rdmd/docs/syntax-extensions) and returns a tree of React components:
|
|
14
|
-
|
|
15
13
|
```jsx
|
|
16
14
|
import React from 'react';
|
|
17
|
-
import
|
|
15
|
+
import rmdx from '@readme/markdown';
|
|
18
16
|
|
|
19
|
-
export default ({ body }) => <div className="markdown-body">{
|
|
17
|
+
export default ({ body }) => <div className="markdown-body">{run(compile(body))}</div>;
|
|
20
18
|
```
|
|
21
19
|
|
|
22
|
-
###
|
|
20
|
+
### API
|
|
21
|
+
|
|
22
|
+
#### `compile`
|
|
23
|
+
|
|
24
|
+
Compiles mdx to js. A wrapper around [`mdx.compile`](https://mdxjs.com/packages/mdx/#compilefile-options)
|
|
25
|
+
|
|
26
|
+
You usually only need this when calling `run` as well. It's been left as a seperate step as a potential caching opportunity.
|
|
27
|
+
|
|
28
|
+
###### Parameters
|
|
29
|
+
|
|
30
|
+
- `string` (`string`) -- An mdx document
|
|
31
|
+
- `opts` ([`CompileOpts`](#compileopts), optional) -- configuration
|
|
32
|
+
|
|
33
|
+
###### Returns
|
|
34
|
+
|
|
35
|
+
compiled code (`string`)
|
|
36
|
+
|
|
37
|
+
#### `run`
|
|
38
|
+
|
|
39
|
+
Run compiled code. A wrapper around [`mdx.run`](https://mdxjs.com/packages/mdx/#runcode-options)
|
|
40
|
+
|
|
41
|
+
> [!CAUTION]
|
|
42
|
+
> This `eval`'s JavaScript.
|
|
43
|
+
|
|
44
|
+
###### Parameters
|
|
45
|
+
|
|
46
|
+
- `string` (`string`) -- A compiled mdx document
|
|
47
|
+
- `opts` (`RunOpts`, optional) -- configuration
|
|
48
|
+
|
|
49
|
+
###### Returns
|
|
50
|
+
|
|
51
|
+
A module ([`RMDXModule`](#rmdxmodule)) of renderable components
|
|
52
|
+
|
|
53
|
+
#### `mdx`
|
|
54
|
+
|
|
55
|
+
Compiles an ast to mdx.
|
|
56
|
+
|
|
57
|
+
#### `mdast`
|
|
58
|
+
|
|
59
|
+
Parses mdx to an mdast.
|
|
60
|
+
|
|
61
|
+
#### `hast`
|
|
62
|
+
|
|
63
|
+
Parses mdx to an hast.
|
|
64
|
+
|
|
65
|
+
#### `plain`
|
|
66
|
+
|
|
67
|
+
> [!NOTE]
|
|
68
|
+
> unimplemented
|
|
69
|
+
|
|
70
|
+
#### `utils`
|
|
71
|
+
|
|
72
|
+
Additional defaults, helpers, components, etc.
|
|
73
|
+
|
|
74
|
+
### `CompileOpts`
|
|
75
|
+
|
|
76
|
+
Extends [`CompileOptions`](https://mdxjs.com/packages/mdx/#compileoptions)
|
|
77
|
+
|
|
78
|
+
###### Additional Properties
|
|
79
|
+
|
|
80
|
+
- `lazyImages` (`boolean`, optional) -- Load images lazily.
|
|
81
|
+
- `safeMode` (`boolean`, optional) -- Extract script tags from `HTMLBlock`s
|
|
82
|
+
- `components` (`Record<string, string>`, optional) -- An object of tag names to mdx.
|
|
83
|
+
- `copyButtons` (`Boolean`, optional) — Automatically insert a button to copy a block of text to the clipboard. Currently used on `<code>` elements.
|
|
84
|
+
|
|
85
|
+
### `RunOpts`
|
|
86
|
+
|
|
87
|
+
Extends [`RunOptions`](https://mdxjs.com/packages/mdx/#runoptions)
|
|
23
88
|
|
|
24
|
-
|
|
89
|
+
###### Additional Properties
|
|
25
90
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
| _`html`_ | transform markdown in to HTML | `text`, `options` |
|
|
31
|
-
| _`mdast`_ | transform markdown to an mdast object | `text`, `options` |
|
|
32
|
-
| _`hast`_ | transform markdown to HAST object | `text`, `options` |
|
|
33
|
-
| _`plain`_ | transform markdown to plain text | `text`, `options` |
|
|
34
|
-
| _`utils`_ | contexts, defaults, helpers, etc. | N/A |
|
|
91
|
+
- `components` (`Record<string, MDXModule>`, optional) -- An object of tag names to executed components.
|
|
92
|
+
- `imports` (`Record<string, unknown>`, optional) -- An object of modules to import.
|
|
93
|
+
- `terms` (`GlossaryTerm[]`, optional)
|
|
94
|
+
- `variables` (`Variables`, optional)
|
|
35
95
|
|
|
36
|
-
###
|
|
96
|
+
### `RMDXModule`
|
|
37
97
|
|
|
38
|
-
|
|
98
|
+
###### Properties
|
|
39
99
|
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
- **`markdownOptions`** — Remark [parser options](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#processorusestringify-options).
|
|
44
|
-
- **`safeMode`** — Render html blocks as `<pre>` elements. We normally allow all manner of html attributes that could potentially execute JavaScript.
|
|
100
|
+
- `default` (`() => MDXContent`) -- The mdx douments default export
|
|
101
|
+
- `toc` (`HastHeading[]`) -- A list of headings in the document
|
|
102
|
+
- `Toc` (`() => MDCContent`) -- A table of contents component
|
|
45
103
|
|
|
46
104
|
## Flavored Syntax
|
|
47
105
|
|
|
48
|
-
Our old editor rendered "Magic Block" components from a custom, JSON-based syntax. To provide seamless backwards-compatibility, our new processor ships with built in support for parsing this old format, and transpiles it straight in to our new, flavored Markdown
|
|
106
|
+
~~Our old editor rendered "Magic Block" components from a custom, JSON-based syntax. To provide seamless backwards-compatibility, our new processor ships with built in support for parsing this old format, and transpiles it straight in to our new, flavored Markdown.~~
|
|
49
107
|
|
|
50
108
|
We've also sprinkled a bit of our own syntactic sugar on top to let you supercharge your docs. [**Learn more about ReadMe's flavored syntax!**](https://docs.readme.com/rdmd/docs/syntax-extensions)
|
|
51
109
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import * as Components from './components';
|
|
2
|
-
import { compile, run, mdx } from './lib';
|
|
2
|
+
import { compile, hast, run, mdast, mdx, plain } from './lib';
|
|
3
3
|
import './styles/main.scss';
|
|
4
4
|
declare const utils: {
|
|
5
5
|
readonly options: any;
|
|
6
6
|
getHref: any;
|
|
7
7
|
calloutIcons: {};
|
|
8
8
|
};
|
|
9
|
-
export { compile, run, mdx, Components, utils };
|
|
10
9
|
export declare const reactProcessor: (opts?: {}) => import("unified").Processor<import("mdast").Root, import("estree").Program, import("estree").Program, import("estree").Program, string>;
|
|
11
10
|
export declare const html: (text: string, opts?: {}) => void;
|
|
12
|
-
export declare const mdast: any;
|
|
13
|
-
export declare const hast: (text: string, opts?: {}) => import("hast").Root;
|
|
14
11
|
export declare const esast: (text: string, opts?: {}) => void;
|
|
15
|
-
export
|
|
12
|
+
export { compile, hast, run, mdast, mdx, plain, Components, utils };
|
package/dist/lib/compile.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { CompileOptions } from '@mdx-js/mdx';
|
|
2
|
-
import { VFileWithToc } from '../types';
|
|
3
2
|
export type CompileOpts = CompileOptions & {
|
|
4
|
-
components?: Record<string, VFileWithToc>;
|
|
5
3
|
lazyImages?: boolean;
|
|
6
4
|
safeMode?: boolean;
|
|
5
|
+
components?: Record<string, string>;
|
|
7
6
|
};
|
|
8
|
-
declare const compile: (text: string, opts?: CompileOpts) =>
|
|
7
|
+
declare const compile: (text: string, { components, ...opts }?: CompileOpts) => string;
|
|
9
8
|
export default compile;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import astProcessor, { MdastOpts, remarkPlugins } from './ast-processor';
|
|
2
2
|
import compile from './compile';
|
|
3
|
+
import hast from './hast';
|
|
4
|
+
import mdast from './mdast';
|
|
3
5
|
import mdx from './mdx';
|
|
6
|
+
import plain from './plain';
|
|
4
7
|
import run from './run';
|
|
5
8
|
export type { MdastOpts };
|
|
6
|
-
export { astProcessor, compile, mdx, run, remarkPlugins };
|
|
9
|
+
export { astProcessor, compile, hast, mdast, mdx, plain, run, remarkPlugins };
|
package/dist/lib/run.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { RunOptions } from '@mdx-js/mdx';
|
|
3
|
-
import { VFileWithToc } from '../types';
|
|
4
3
|
import { GlossaryTerm } from '../contexts/GlossaryTerms';
|
|
4
|
+
import { CustomComponents } from '../types';
|
|
5
5
|
interface Variables {
|
|
6
6
|
user: Record<string, string>;
|
|
7
7
|
defaults: {
|
|
@@ -10,15 +10,15 @@ interface Variables {
|
|
|
10
10
|
}[];
|
|
11
11
|
}
|
|
12
12
|
export type RunOpts = Omit<RunOptions, 'Fragment'> & {
|
|
13
|
-
components?:
|
|
13
|
+
components?: CustomComponents;
|
|
14
14
|
imports?: Record<string, unknown>;
|
|
15
15
|
baseUrl?: string;
|
|
16
16
|
terms?: GlossaryTerm[];
|
|
17
17
|
variables?: Variables;
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
declare const run: (stringOrFile: string | VFileWithToc, _opts?: RunOpts) => Promise<{
|
|
19
|
+
declare const run: (string: string, _opts?: RunOpts) => Promise<{
|
|
21
20
|
default: () => React.JSX.Element;
|
|
22
|
-
toc: ()
|
|
21
|
+
toc: import("../types").IndexableElements[];
|
|
22
|
+
Toc: () => React.JSX.Element;
|
|
23
23
|
}>;
|
|
24
24
|
export default run;
|