Skip to content

readmeio/markdown

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3,004 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@readme/markdown

ReadMe's flavored Markdown parser and MDX rendering engine. RDMD CI Status

npm install --save @readme/markdown

Usage

import React from 'react';
import rmdx from '@readme/markdown';

export default ({ body }) => <div className="markdown-body">{run(compile(body))}</div>;

API

compile

Compiles mdx to js. A wrapper around mdx.compile

You usually only need this when calling run as well. It's been left as a seperate step as a potential caching opportunity.

Parameters
  • string (string) -- An mdx document
  • opts (CompileOpts, optional) -- configuration
Returns

compiled code (string)

run

Run compiled code. A wrapper around mdx.run

Caution

This eval's JavaScript.

Parameters
  • string (string) -- A compiled mdx document
  • opts (RunOpts, optional) -- configuration
Returns

A module (RMDXModule) of renderable components

mdx

Compiles an ast to mdx.

mdast

Parses mdx to an mdast.

hast

Parses mdx to an hast.

plain

Note

unimplemented

utils

Additional defaults, helpers, components, etc.

CompileOpts

Extends CompileOptions

Additional Properties
  • lazyImages (boolean, optional) -- Load images lazily.
  • safeMode (boolean, optional) -- Extract script tags from HTMLBlocks
  • components (Record<string, string>, optional) -- An object of tag names to mdx.
  • copyButtons (Boolean, optional) — Automatically insert a button to copy a block of text to the clipboard. Currently used on <code> elements.

RunOpts

Extends RunOptions

Additional Properties
  • components (Record<string, MDXModule>, optional) -- An object of tag names to executed components.
  • imports (Record<string, unknown>, optional) -- An object of modules to import.
  • 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

Flavored Syntax

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.

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!

Local Development

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!

Environment setup

Running the browser tests requires docker. Follow the docker install instructions for mac. You may want to increase the memory usage. If you have not already, you'll need to create an account for docker hub and sign-in locally.

Running visual regression tests

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:

make updateSnapshot

Credits

About

ReadMe's flavored Markdown parser and React-based rendering engine.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

40 stars

Watchers

14 watching

Forks

Contributors