https://github.com/readmeio/markdown
ReadMe's flavored Markdown parser and React-based rendering engine.
https://github.com/readmeio/markdown
gfm markdown mdx rdmd react
Last synced: about 1 month ago
JSON representation
ReadMe's flavored Markdown parser and React-based rendering engine.
- Host: GitHub
- URL: https://github.com/readmeio/markdown
- Owner: readmeio
- License: isc
- Created: 2020-07-28T18:07:41.000Z (almost 6 years ago)
- Default Branch: next
- Last Pushed: 2026-06-03T21:34:19.000Z (about 1 month ago)
- Last Synced: 2026-06-03T23:13:29.954Z (about 1 month ago)
- Topics: gfm, markdown, mdx, rdmd, react
- Language: TypeScript
- Homepage: https://rdmd.readme.io
- Size: 173 MB
- Stars: 40
- Watchers: 14
- Forks: 18
- Open Issues: 37
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
ReadMe's MDX rendering engine and custom component collection.
Use ReadMe? Learn more about our upcoming move to MDX!
## Usage
To use the engine, install it from NPM:
```
npm install --save @readme/markdown
```
Then [`compile`](#compile) and [`run`](#run) your MDX:
```jsx
import RMDX from '@readme/markdown';
export default ({ body }) =>
{RMDX.run(RMDX.compile(body))};
```
## API
### `compile`
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.
#### Parameters
- **`string`** (`string`)—an MDX document
- **`opts`** ([`CompileOpts`](#compileopts), optional)—a configuration object
#### Returns
A string of compiled Javascript module code.
### `run`
> [!CAUTION]
> 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!
#### Parameters
- **`string`** (`string`)—a compiled mdx document
- **`opts`** (`RunOpts`, optional)—configuration
#### Returns
An [`RMDXModule`](#rmdxmodule) of renderable components.
### `mdx`
Compiles an AST to a string of MDX syntax.
#### Parameters
- **`tree`** (`object`)—an abstract syntax tree
- **`opts`** ([`Options`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options '`remark-stringify` Options type'))—`remark-stringify` configuration.
#### Returns
An MDX string.
### Other Methods
- **`mdast`**: parse MDX syntax to MDAST.
- **`hast`**: parse MDX syntax to HAST.
- **`plain`**: parse MDX to a plaintext string with all Markdown syntax removed. (This _does not_ `eval` the doc.)
- **`tags`**: get a list of tag names from the doc. (This _does not_ `eval` the doc.)
- **`utils`**: additional defaults, helper methods, components, and so on.
## Types
### `CompileOpts`
Extends [`CompileOptions`](https://mdxjs.com/packages/mdx/#compileoptions)
##### Additional Properties
- **`lazyImages`** (`boolean`, optional)—load images lazily
- **`safeMode`** (`boolean`, optional)—extract script tags from `HTMLBlock`s
- **`components`** (`Record`, optional)—an object of tag names to mdx.
- **`copyButtons`** (`Boolean`, optional) — add a copy button to code blocks
### `RunOpts`
Extends [`RunOptions`](https://mdxjs.com/packages/mdx/#runoptions)
##### Additional Properties
- **`components`** (`Record`, optional)—a set of custom MDX components
- **`imports`** (`Record`, optional)—an set of modules to import globally
- **`terms`** (`GlossaryTerm[]`, optional)
- **`variables`** (`Variables`, optional)—an object containing [user variables](https://github.com/readmeio/variable)
### `RMDXModule`
##### Properties
- **`default`** (`() => MDXContent`)—the MDX douments default export
- **`toc`** (`HastHeading[]`)—a list of headings in the document
- **`Toc`** (`() => MDCContent`)—a table of contents component
## Local development and testing
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`!
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).
### Linking Changes to the Main Repo
To test local changes in the main readme app, use `npm pack` (not `npm link`) and clear the webpack cache:
**In this repo, run:**
```
npm ci && npm run build
```
**In the main app repo:**
Add to `.env`:
```
MARKDOWN_DIR={{path to local markdown repo}}
```
Run:
```
make link-markdown && rm -rf webpack-cache && make webpack && make start
```
> **Note:** You must clear `webpack-cache` after every reinstall or the app will serve the old version.
### Linking Changes to Storybook
`npm link` works with the storybook app:
**In this repo, run:**
```
npm link && npm run watch
```
**In the main app repo, run:**
```
npm link $PATH_TO_LOCAL_MARKDOWN_REPO
```
## Releases
First, update `main` with what’s on `next`:
```
git switch next
git pull
git switch main
git pull
git merge --no-ff next
git push
```
WAIT until the build is finished, then update `next`:
```
git pull
git switch next
git merge main
git push
```