@readme/markdown 6.75.0-beta.50 → 6.75.0-beta.52

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 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 rdmd from '@readme/markdown';
15
+ import rmdx from '@readme/markdown';
18
16
 
19
- export default ({ body }) => <div className="markdown-body">{rdmd(body)}</div>;
17
+ export default ({ body }) => <div className="markdown-body">{run(compile(body))}</div>;
20
18
  ```
21
19
 
22
- ### Export Methods
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
- In addition to the default React processor, the package exports some other methods for transforming ReadMe-flavored markdown:
89
+ ###### Additional Properties
25
90
 
26
- | Export | Description | Arguments |
27
- | --------: | :--------------------------------------------- | :---------------- |
28
- | _`react`_ | _(default)_ returns a VDOM tree object | `text`, `options` |
29
- | _`md`_ | transform mdast in to ReadMe-flavored markdown | `tree`, `options` |
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
- ### Settings & Options
96
+ ### `RMDXModule`
37
97
 
38
- Each processor method takes an options object which you can use to adjust the output HTML or React tree. These options include:
98
+ ###### Properties
39
99
 
40
- - **`compatibilityMode`** Enable [compatibility features](https://github.com/readmeio/api-explorer/issues/668) from our old markdown engine.
41
- - **`copyButtons`** Automatically insert a button to copy a block of text to the clipboard. Currently used on `<code>` elements.
42
- - **`correctnewlines`** Render new line delimeters as `<br>` tags.
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 declare const plain: (text: string, opts?: {}) => void;
12
+ export { compile, hast, run, mdast, mdx, plain, Components, utils };
@@ -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) => VFileWithToc;
7
+ declare const compile: (text: string, { components, ...opts }?: CompileOpts) => string;
9
8
  export default compile;
@@ -0,0 +1,5 @@
1
+ interface Options {
2
+ components?: Record<string, string>;
3
+ }
4
+ declare const hast: (text: string, opts?: Options) => import("hast").Root;
5
+ export default hast;
@@ -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 };
@@ -0,0 +1,2 @@
1
+ declare const mdast: any;
2
+ export default mdast;
@@ -0,0 +1,3 @@
1
+ import { Nodes } from 'hast';
2
+ declare const plain: (node: Nodes, opts?: {}) => string | number | true | (string | number)[];
3
+ export default plain;
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?: ComponentOpts;
13
+ components?: CustomComponents;
14
14
  imports?: Record<string, unknown>;
15
15
  baseUrl?: string;
16
16
  terms?: GlossaryTerm[];
17
17
  variables?: Variables;
18
18
  };
19
- type ComponentOpts = Record<string, (props: any) => React.ReactNode>;
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: () => React.JSX.Element;
21
+ toc: import("../types").IndexableElements[];
22
+ Toc: () => React.JSX.Element;
23
23
  }>;
24
24
  export default run;