Skip to content

Commit 389ce09

Browse files
committed
Add improved docs
1 parent 279564f commit 389ce09

File tree

1 file changed

+148
-45
lines changed

1 file changed

+148
-45
lines changed

readme.md

Lines changed: 148 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,82 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

11-
**[micromark][]** extension to support MDX (agnostic to JS).
12-
Use [`micromark-extension-mdxjs`][mdxjs] instead to support MDX.js.
13-
14-
This package provides the low-level modules for integrating with the micromark
15-
tokenizer but has no handling of compiling to HTML: go to a syntax tree instead.
11+
[micromark][] extensions to support [MDX][mdxjs], unaware of JavaScript.
12+
13+
## Contents
14+
15+
* [What is this?](#what-is-this)
16+
* [When to use this](#when-to-use-this)
17+
* [Install](#install)
18+
* [Use](#use)
19+
* [API](#api)
20+
* [`mdx()`](#mdx)
21+
* [Authoring](#authoring)
22+
* [Syntax](#syntax)
23+
* [Errors](#errors)
24+
* [Types](#types)
25+
* [Compatibility](#compatibility)
26+
* [Security](#security)
27+
* [Related](#related)
28+
* [Contribute](#contribute)
29+
* [License](#license)
30+
31+
## What is this?
32+
33+
This package contains an extension that adds support for the syntax enabled
34+
by [MDX][mdxjs] to [`micromark`][micromark].
35+
This extension is used inside MDX.
36+
It supports expressions, JSX, and turns some markdown features off.
37+
It is not aware of the syntax of JavaScript inside expressions and does not
38+
support export/imports.
1639

1740
## When to use this
1841

19-
You should probably use [`micromark-extension-mdxjs`][mdxjs] instead, which
20-
supports JavaScript.
21-
Alternatively, if you don’t want JavaScript-aware parsing, use this package.
42+
You can use this extension when you are working with [`micromark`][micromark].
2243

23-
If you don’t need all of MDX, the extensions can be used separately:
44+
This project is useful when you want to support MDX, unaware of JavaScript, for
45+
example because expressions can include Rust or variables or whatnot.
46+
If you want to be aware of JavaScript, use
47+
[`micromark-extension-mdxjs`][micromark-extension-mdxjs].
2448

25-
* [`micromark/micromark-extension-mdx-expression`][mdx-expression]
26-
— support MDX (or MDX.js) expressions
27-
* [`micromark/micromark-extension-mdx-jsx`][mdx-jsx]
28-
— support MDX (or MDX.js) JSX
29-
* [`micromark/micromark-extension-mdx-md`][mdx-md]
30-
— turn some markdown features off for MDX (or MDX.js)
49+
Alternatively, you can also use the underlying syntax extensions separately:
3150

32-
## Install
51+
* [`micromark-extension-mdx-expression`][micromark-extension-mdx-expression]
52+
— support MDX expressions
53+
* [`micromark-extension-mdx-jsx`][micromark-extension-mdx-jsx]
54+
— support MDX JSX
55+
* [`micromark-extension-mdx-md`][micromark-extension-mdx-md]
56+
— turn some CommonMark features off
57+
58+
When you need a syntax tree, combine this package with
59+
[`mdast-util-mdx`][mdast-util-mdx].
3360

34-
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
35-
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
61+
All these packages are used in [`remark-mdx`][remark-mdx], which focusses on
62+
making it easier to transform content by abstracting these internals away.
63+
64+
## Install
3665

37-
[npm][]:
66+
This package is [ESM only][esm].
67+
In Node.js (version 16+), install with [npm][]:
3868

3969
```sh
4070
npm install micromark-extension-mdx
4171
```
4272

73+
In Deno with [`esm.sh`][esmsh]:
74+
75+
```js
76+
import {mdx} from 'https://esm.sh/micromark-extension-mdx@1'
77+
```
78+
79+
In browsers with [`esm.sh`][esmsh]:
80+
81+
```html
82+
<script type="module">
83+
import {mdx} from 'https://esm.sh/micromark-extension-mdx@1?bundle'
84+
</script>
85+
```
86+
4387
## Use
4488

4589
```js
@@ -57,35 +101,78 @@ Yields:
57101
<p>a c d</p>
58102
```
59103

60-
…which is rather useless: go to a syntax tree with
61-
[`mdast-util-from-markdown`][from-markdown] and
104+
…which is useless: go to a syntax tree with
105+
[`mdast-util-from-markdown`][mdast-util-from-markdown] and
62106
[`mdast-util-mdx`][mdast-util-mdx] instead.
63107

64108
## API
65109

66-
This package exports the following identifiers: `mdx`.
110+
This package exports the identifier [`mdx`][api-mdx].
67111
There is no default export.
68112

113+
The separate extensions support the [`development` condition][development].
114+
Run `node --conditions development module.js` to get instrumented dev code.
115+
Without this condition, production code is loaded.
116+
69117
### `mdx()`
70118

71-
A function that can be called which returns an extension for micromark to parse
72-
MDX (can be passed in `extensions`).
73-
There are no options yet.
119+
Create an extension for `micromark` to enable MDX syntax, unaware of JavaScript.
120+
121+
###### Returns
122+
123+
Extension for `micromark` that can be passed in `extensions` to enable MDX
124+
syntax, unaware of JavaScript ([`Extension`][micromark-extension]).
125+
126+
## Authoring
127+
128+
For recommendations on how to author MDX, see each corresponding readme:
129+
130+
* [expressions](https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-extension-mdx-expression#authoring)
131+
* [JSX](https://github.com/micromark/micromark-extension-mdx-jsx#authoring)
132+
* [CommonMark features not in MDX](https://github.com/micromark/micromark-extension-mdx-md#authoring)
133+
134+
## Syntax
135+
136+
For info on the syntax of these features, see each corresponding readme:
137+
138+
* [expressions](https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-extension-mdx-expression#syntax)
139+
* [JSX](https://github.com/micromark/micromark-extension-mdx-jsx#syntax)
140+
* CommonMark features not in MDX: n/a
141+
142+
## Errors
143+
144+
For info on what errors are thrown, see each corresponding readme:
145+
146+
* [expressions](https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-extension-mdx-expression#errors)
147+
* [JSX](https://github.com/micromark/micromark-extension-mdx-jsx#errors)
148+
* CommonMark features not in MDX: n/a
149+
150+
## Types
151+
152+
This package is fully typed with [TypeScript][].
153+
It exports no additional types.
154+
155+
## Compatibility
156+
157+
Projects maintained by the unified collective are compatible with all maintained
158+
versions of Node.js.
159+
As of now, that is Node.js 16+.
160+
Our projects sometimes work with older versions, but this is not guaranteed.
161+
162+
These extensions work with `micromark` version 3+.
163+
164+
## Security
165+
166+
This package is safe.
74167

75168
## Related
76169

77-
* [`micromark/micromark`][micromark]
78-
— the smallest commonmark-compliant markdown parser that exists
79-
* [`micromark/micromark-extension-mdxjs`][mdxjs]
80-
— micromark extension to support MDX.js
81-
* [`micromark/micromark-extension-mdx-expression`][mdx-expression]
82-
— micromark extension to support MDX (or MDX.js) expressions
83-
* [`micromark/micromark-extension-mdx-jsx`][mdx-jsx]
84-
— micromark extension to support MDX (or MDX.js) JSX
85-
* [`micromark/micromark-extension-mdx-md`][mdx-md]
86-
— micromark extension to support misc MDX changes
87-
* [`syntax-tree/mdast-util-mdx`][mdast-util-mdx]
88-
— mdast utility to support MDX (or MDX.js)
170+
* [`micromark-extension-mdxjs`][micromark-extension-mdxjs]
171+
— support MDX aware of JS
172+
* [`mdast-util-mdx`][mdast-util-mdx]
173+
— support MDX in mdast
174+
* [`remark-mdx`][remark-mdx]
175+
— support MDX syntax in remark
89176

90177
## Contribute
91178

@@ -131,26 +218,42 @@ abide by its terms.
131218

132219
[npm]: https://docs.npmjs.com/cli/install
133220

221+
[esmsh]: https://esm.sh
222+
134223
[license]: license
135224

136225
[author]: https://wooorm.com
137226

138-
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
227+
[contributing]: https://github.com/micromark/.github/blob/main/contributing.md
228+
229+
[support]: https://github.com/micromark/.github/blob/main/support.md
230+
231+
[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md
139232

140-
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
233+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
141234

142-
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
235+
[typescript]: https://www.typescriptlang.org
236+
237+
[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions
143238

144239
[micromark]: https://github.com/micromark/micromark
145240

146-
[mdxjs]: https://github.com/micromark/micromark-extension-mdxjs
241+
[micromark-extension]: https://github.com/micromark/micromark#syntaxextension
242+
243+
[micromark-extension-mdxjs]: https://github.com/micromark/micromark-extension-mdxjs
244+
245+
[micromark-extension-mdx-expression]: https://github.com/micromark/micromark-extension-mdx-expression
147246

148-
[mdx-expression]: https://github.com/micromark/micromark-extension-mdx-expression
247+
[micromark-extension-mdx-jsx]: https://github.com/micromark/micromark-extension-mdx-jsx
149248

150-
[mdx-jsx]: https://github.com/micromark/micromark-extension-mdx-jsx
249+
[micromark-extension-mdx-md]: https://github.com/micromark/micromark-extension-mdx-md
151250

152-
[mdx-md]: https://github.com/micromark/micromark-extension-mdx-md
251+
[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
153252

154253
[mdast-util-mdx]: https://github.com/syntax-tree/mdast-util-mdx
155254

156-
[from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
255+
[remark-mdx]: https://mdxjs.com/packages/remark-mdx/
256+
257+
[mdxjs]: https://mdxjs.com
258+
259+
[api-mdx]: #mdx

0 commit comments

Comments
 (0)