NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm · #1803 most downloaded on npm
React component to render markdown
Last release 2 years ago
no release in 18 months
Ships unpredictably
gaps range from 1 weeks to 1.1 years
Nearly every release is documented
notes for 59 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
11 years old
98 releases · first in 2015
939c667 Add fallback prop to MarkdownHooks by @remcohaszing in #897
fallback prop to MarkdownHooksMarkdownHooksFull Changelog: 10.0.1...10.1.0
7c17ede Fix TypeScript performance around components by @remcohaszing in #893
Full Changelog: 10.0.0...10.0.1
One column per quarter.
aaaa40b Remove support for className prop see “Remove className”
className propFull Changelog: 9.1.0...10.0.0
aaaa40b
Remove support for className prop
migrate: see “Remove className” belowclassNameThe className prop was removed.
If you want to add classes to some element that wraps the markdown
you can explicitly write that element and add the class to it.
You can then choose yourself which tag name to use and whether to add other
props.
Before:
<Markdown className="markdown-body">{markdown}</Markdown>
After:
<div className="markdown-body">
<Markdown>{markdown}</Markdown>
</div>
6ce120e Add support for async plugins by @wooorm in #890
Full Changelog: 9.0.3...9.1.0
(same as 9.0.2 but now with d.ts files)
(same as 9.0.2 but now with d.ts files)
Full Changelog: 9.0.2...9.0.3
b151a90 Fix types for React 19 by @remcohaszing in #879
@import to import typesFull Changelog: 9.0.1...9.0.2
d8e3787 Fix double encoding in new url transform
Full Changelog: 9.0.0...9.0.1
b67d714 Change to require Node.js 16 migrate : update too
exports@types/hast, utilities, plugins, etctransformImageUri, transformLinkUri w/ urlTransformurlTransformlinkTarget optionlinkTarget4346276 Remove support for passing custom props to componentsincludeElementIndex, Remove rawSourcePos, Remove sourcePos, Remove extra props passed to certain componentsc0dfbd6 Remove UMD bundle from packageesm.sh or a CDN or soe12b5e9 Remove prop-types4eb7aa0 Change to throw errors for removed props8aabf74 Change to improve error messagesFull Changelog: 8.0.7...9.0.0
b67d714
Change to require Node.js 16ec2b134
Change to require React 18bf5824f
Change to use exportsc383a45
Update @types/hast, utilities, plugins, etceca5e6b
08ead9e
Replace transformImageUri, transformLinkUri w/ urlTransformurlTransform” belowde29396
Remove linkTarget optionlinkTarget” below4346276
Remove support for passing custom props to componentsincludeElementIndex”, “Remove rawSourcePos”,
“Remove sourcePos”, “Remove extra props passed to certain components”
belowc0dfbd6
Remove UMD bundle from packageesm.sh or a CDN or soe12b5e9
Remove prop-types4eb7aa0
Change to throw errors for removed props8aabf74
Change to improve error messagesurlTransformThe transformImageUri and transformLinkUri were removed.
Having two functions is a bit much, particularly because there are more URLs
you might want to change (or which might be unsafe so we make them safe).
And their name and APIs were a bit weird.
You can use the new urlTransform prop instead to change all your URLs.
linkTargetThe linkTarget option was removed; you should likely not set targets.
If you want to, use
rehype-external-links.
includeElementIndexThe includeElementIndex option was removed, so index is never passed to
components.
Write a plugin to pass index:
<details> <summary>Show example of plugin</summary>
import {visit} from 'unist-util-visit'
function rehypePluginAddingIndex() {
/**
* @param {import('hast').Root} tree
* @returns {undefined}
*/
return function (tree) {
visit(tree, function (node, index) {
if (node.type === 'element' && typeof index === 'number') {
node.properties.index = index
}
})
}
}
</details>
rawSourcePosThe rawSourcePos option was removed, so sourcePos is never passed to
components.
All components are passed node, so you can get node.position from them.
sourcePosThe sourcePos option was removed, so data-sourcepos is never passed to
elements.
Write a plugin to pass index:
<details> <summary>Show example of plugin</summary>
import {stringifyPosition} from 'unist-util-stringify-position'
import {visit} from 'unist-util-visit'
function rehypePluginAddingIndex() {
/**
* @param {import('hast').Root} tree
* @returns {undefined}
*/
return function (tree) {
visit(tree, function (node) {
if (node.type === 'element') {
node.properties.dataSourcepos = stringifyPosition(node.position)
}
})
}
}
</details>
When overwriting components, these props are no longer passed:
inline on code
— create a plugin or use pre for the blocklevel on h1, h2, h3, h4, h5, h6
— check node.tagName insteadchecked on li
— check task-list-item class or check props.childrenindex on li
— create a pluginordered on li
— create a plugin or check the parentdepth on ol, ul
— create a pluginordered on ol, ul
— check node.tagName insteadisHeader on td, th
— check node.tagName insteadisHeader on tr
— create a plugin or check childrenc289176 Fix performance for keys by @wooorm in #738
c289176
Fix performance for keys
by @wooorm
in #7389034dbd
Fix types in syntax highlight example
by @dlqqq
in #736Full Changelog: https://github.com/remarkjs/react-markdown/compare/8.0.6...8.0.7
33ab015 Update to TS 5 by @Methuselah96 in #734
33ab015 Update to TS 5Full Changelog: 8.0.5...8.0.6
402fea3 Fix typo in plugins deprecation message by @marc2332 in https://github.com/remarkjs/react-markdown/pull/719
node16 module resolution in tsconfig.json
by @ChristianMurphy in https://github.com/remarkjs/react-markdown/pull/723plugins deprecation message
by @marc2332 in https://github.com/remarkjs/react-markdown/pull/719defaultProps
by @Lepozepo in https://github.com/remarkjs/react-markdown/pull/718Full Changelog: https://github.com/remarkjs/react-markdown/compare/8.0.4...8.0.5
9b20440 Fix type of td, th props by @lucasassisrosa in https://github.com/remarkjs/react-markdown/pull/714
td, th props
by @lucasassisrosa in https://github.com/remarkjs/react-markdown/pull/714alt on img in docs
by @cballenar in https://github.com/remarkjs/react-markdown/pull/692Full Changelog: https://github.com/remarkjs/react-markdown/compare/8.0.3...8.0.4
9b20440
Fix type of td, th propscfe075b
Add clarification of alt on img in docsa2fb833 Fix prop types of plugins by @starpit in https://github.com/remarkjs/react-markdown/pull/683
Full Changelog: https://github.com/remarkjs/react-markdown/compare/8.0.2...8.0.3
704c3c6 Fix TypeScript bug by adding workaround by @Methuselah96 in https://github.com/remarkjs/react-markdown/pull/676
react-isFull Changelog: https://github.com/remarkjs/react-markdown/compare/8.0.1...8.0.2
c23ecf6 Add missing dependency for types by @Methuselah96 in https://github.com/remarkjs/react-markdown/pull/675
Full Changelog: https://github.com/remarkjs/react-markdown/compare/8.0.0...8.0.1
c23ecf6
Add missing dependency for types`cd845c9` Remove deprecated plugins option (migrate by renaming it to `remarkPlugins`)
cd845c9 Remove deprecated plugins option
(migrate by renaming it to remarkPlugins)36e4916 Update remark-rehype, add support for passing it options
by @peolic in #669
(migrate by removing remark-footnotes and updating remark-gfm if you were using them, otherwise you shouldn’t notice this)Full Changelog: https://github.com/remarkjs/react-markdown/compare/7.1.2...8.0.0
656a4fa Fix ref in types by @ChristianMurphy in https://github.com/remarkjs/react-markdown/pull/668
ref in types
by @ChristianMurphy in https://github.com/remarkjs/react-markdown/pull/668Full Changelog: https://github.com/remarkjs/react-markdown/compare/7.1.1...7.1.2
4185f06 Add improved docs by @wooorm in https://github.com/remarkjs/react-markdown/pull/657
Full Changelog: https://github.com/remarkjs/react-markdown/compare/7.1.0...7.1.1
7b8a829 Add support for SpecialComponents to be any ComponentType by @Methuselah96 in https://github.com/remarkjs/react-markdown/pull/640
SpecialComponents to be any ComponentType
by @Methuselah96 in https://github.com/remarkjs/react-markdown/pull/640Full Changelog: https://github.com/remarkjs/react-markdown/compare/7.0.1...7.1.0
7b8a829
Add support for SpecialComponents to be any ComponentTypea7c26fc
Remove warning on whitespace in tables`ec387c2` Add improved type for linkTarget as string
Please see `changelog.md`
Please see changelog.md
`13367ed` Fix types to include each element w/ its properties
`cefc02d` Add string type for classNames
`2e956be` Fix whitespace in table elements
Please see `changelog.md`
Please see changelog.md
Welcome to version 6. This a major release and therefore contains breaking changes.
renderers to componentsreact-markdown used to let you define components for markdown constructs
(link, delete, break, etc).
This proved complex as users didn’t know about those names or markdown
peculiarities (such as that there are fully formed links and link references).
See GH-549 for more
on why this changed.
See Appendix B: Components in
readme.md
for more on components.
<details> <summary>Show example of needed change</summary>
Before (broken):
<Markdown
renderers={{
// Use a fancy hr
thematicBreak: ({node, ...props}) => <MyFancyRule {...props} />
}}
>{`***`}</Markdown>
Now (fixed):
<Markdown
components={{
// Use a fancy hr
hr: ({node, ...props}) => <MyFancyRule {...props} />
}}
>{`***`}</Markdown>
</details>
<details> <summary>Show conversion table</summary>
Type (renderers) |
Tag names (components) |
|---|---|
blockquote |
blockquote |
break |
br |
code, inlineCode |
code, pre* |
definition |
† |
delete |
del‡ |
emphasis |
em |
heading |
h1, h2, h3, h4, h5, h6§ |
html, parsedHtml, virtualHtml |
‖ |
image, imageReference |
img† |
link, linkReference |
a† |
list |
ol, ul¶ |
listItem |
li |
paragraph |
p |
root |
** |
strong |
strong |
table |
table‡ |
tableHead |
thead‡ |
tableBody |
tbody‡ |
tableRow |
tr‡ |
tableCell |
td, th‡ |
text |
|
thematicBreak |
hr |
inline
prop.
Block code is also wrapped in a pre[text](url)) and reference ([text][id]) style links and
images (and their definitions) are now resolved and treated the sameremark-gfmlevel
proprehype-raw (see below), components for those elements
can also be used (for example, abbr for
<abbr title="HyperText Markup Language">HTML</abbr>)ordered
propReactMarkdown in a component instead</details>
rehypePluginsWe’ve added another plugin system: rehype. It’s similar to remark (what we’re using for markdown) but for HTML.
There are many rehype plugins.
Some examples are
@mapbox/rehype-prism
(syntax highlighting with Prism),
rehype-katex
(rendering math with KaTeX), or
rehype-autolink-headings
(adding links to headings).
See List of plugins for more plugins.
<details> <summary>Show example of feature</summary>
import rehypeHighlight from 'rehype-highlight'
<Markdown rehypePlugins={[rehypeHighlight]}>{`~~~js
console.log(1)
~~~`}</Markdown>
</details>
In a lot of cases, you should not use HTML in markdown: it’s most always unsafe.
And it defeats much of the purpose of this project (not relying on
dangerouslySetInnerHTML).
react-markdown used to have an opt-in HTML parser with a bunch of bugs.
As we now support rehype plugins, we can defer that work to a rehype plugin.
To support HTML in markdown with react-markdown, use
rehype-raw.
The astPlugins and allowDangerousHtml (previously called escapeHtml) props
are no longer needed and were removed.
When using rehype-raw, you should probably use
rehype-sanitize
too.
<details> <summary>Show example of needed change</summary>
Before (broken):
import MarkdownWithHtml from 'react-markdown/with-html'
<MarkdownWithHtml>{`# Hello, <i>world</i>!`}</MarkdownWithHtml>
Now (fixed):
import Markdown from 'react-markdown'
import rehypeRaw from 'rehype-raw'
import rehypeSanitize from 'rehype-sanitize'
<Markdown rehypePlugins={[rehypeRaw, rehypeSanitize]}>{`# Hello, <i>world</i>!`}</Markdown>
</details>
source to childrenInstead of passing a source pass children instead:
<details> <summary>Show example of needed change</summary>
Before (broken):
<Markdown source="some\nmarkdown"></Markdown>
Now (fixed):
<Markdown>{`some
markdown`}</Markdown>
Or (also fixed):
<Markdown children={`some
markdown`} />
</details>
allowNode, allowedTypes, and disallowedTypesSimilar to the renderers to components change, the filtering options
also changed from being based on markdown names towards being based on HTML
names: allowNode to allowElement, allowedTypes to allowedElements, and
disallowedTypes to disallowedElements.
<details> <summary>Show example of needed change</summary>
Before (broken):
<Markdown
// Skip images
disallowedTypes={['image']}
>{``}</Markdown>
Now (fixed):
<Markdown
// Skip images
disallowedElements={['img']}
>{``}</Markdown>
Before (broken):
<Markdown
// Skip h1
allowNode={(node) => node.type !== 'heading' || node.depth !== 1}
>{`# main heading`}</Markdown>
Now (fixed):
<Markdown
// Skip h1
allowElement={(element) => element.tagName !== 'h1'}
>{`# main heading`}</Markdown>
</details>
includeNodeIndex to includeElementIndexSimilar to the renderers to components change, this option to pass more info
to components also changed from being based on markdown to being based on HTML.
<details> <summary>Show example of needed change</summary>
Before (broken):
<Markdown
includeNodeIndex={true}
renderers={{
paragraph({node, index, parentChildCount, ...props}) => <MyFancyParagraph {...props} />
}}
>{`Some text`}</Markdown>
Now (fixed):
<Markdown
includeElementIndex={true}
components={{
p({node, index, siblingsCount, ...props}) => <MyFancyParagraph {...props} />
}}
>{`Some text`}</Markdown>
</details>
transformLinkUri, linkTargetThe second parameter of these functions (to rewrite href on a or to define
target on a) are now hast (HTML AST)
instead of mdast (markdown AST).
transformImageUriThe second parameter of this function was always undefined and the fourth was
the alt (string) on the image.
The second parameter is now that alt.
We now use ES2015 (such as Object.assign) and removed certain hacks to work
with React 15 and older.
`bb0bdde` Unlock peer dependency on React to allow v17
`4dadaba` Fix to allow combining allowedTypes, unwrapDisallowed in types
4dadaba
Fix to allow combining allowedTypes, unwrapDisallowed in types`c3dc5ee` Fix to not crash on empty text nodes
c3dc5ee
Fix to not crash on empty text nodesThis contains the raw mdast AST node, which opens up a number of interesting possibilities. The breaking change is for renderers which blindly spread…
This project is now maintained by the unified collective, which also houses the
underlying tools used in react-markdown: hundreds of projects for working with
markdown and markup related things (including MDX).
We have cleaned the project: updated dependencies, improved
docs/tests/coverage/types, cleaned the issue tracker, and fixed a couple of
bugs, but otherwise much should be the same.
remark-parseThe parser used in react-markdown has been upgraded to the latest version.
It is now 100% CommonMark compliant: that means it works the same as in other
places, such as Discourse, Reddit, Stack Overflow, and GitHub.
Note that GitHub does extend CommonMark: to match how Markdown works on GitHub,
use the remark-gfm plugin.
nodeA new node prop is passed to all non-tag/non-fragment renderers.
This contains the raw mdast AST node,
which opens up a number of interesting possibilities.
The breaking change is for renderers which blindly spread their props to an
underlying component/tag.
For instance:
<ReactMarkdown renderers={{link: props => <a {...props} />}} … />
Should now be written as:
<ReactMarkdown renderers={{link: ({node, ...props}) => <a {...props} />}} … />
tight property replaced by spreadPreviously, the tight property would hint as to whether or not list items
should be wrapped in paragraphs.
This logic has now been replaced by a new spread property, which behaves
slightly differently.
Read more.
(Typings) Fix incorrect typescript definitions (Peng Guanwen)
(Typings) Add typings for react-markdown/html-parser (Peng Guanwen)
react-markdown/html-parser (Peng Guanwen)(Typings) Inline RemarkParseOptions for now (Espen Hovlandsdal)
RemarkParseOptions for now (Espen Hovlandsdal)(Typings) Fix incorrect import - RemarkParseOptions (Jakub Chrzanowski)
RemarkParseOptions (Jakub Chrzanowski)Add support for plugins that use AST transformations (Frankie Ali)
parserOptions to type definitions (Ted Piotrowski)Add prop parserOptions to specify options for remark-parse (Kelvin Chan)
parserOptions to specify options for remark-parse (Kelvin Chan)(Typings) Make transformLinkUri & transformImageUri actually nullable (Florentin Luca Rieger)
Fix HTML parsing of elements with a single child vs. multiple children (Nicolas Venegas)
Fix matching of replaced non-void elements in HTML parser plugin (Nicolas Venegas)
Mitigate regex ddos by upgrading html-to-react (Christoph Werner)
Nothing published for this version
Upgrade dependencies (Espen Hovlandsdal)
Output paragraph element for last item in loose list (Jeremy Moseley)
Fix text rendering in React versions lower than or equal to 15 (Espen Hovlandsdal)
\[TypeScript] Fix TypeScript index signature for renderers (Linus Unnebäck)
text is now a first-class node + renderer — if you are using allowedNodes, it needs to be included in this list. Since it is now a React component, it
text is now a first-class node + renderer
— if you are using allowedNodes, it needs to be included in this list.
Since it is now a React component, it will be passed an object of props
instead of the old approach where a string was passed.
children will contain the actual text string.className prop is provided, a fragment will be
used instead of a div.
To always render a div, pass 'div' as the root renderer.window.ReactMarkdown instead
of window.reactMarkdownrenderers (Linus Unnebäck)Add support for passing index info to renderers (Beau Roberts)
Allow specifying target attribute for links (Marshall Smith)
target attribute for links (Marshall Smith)Bump dependency for mdast-add-list-metadata as it was using ES6 features (Espen Hovlandsdal)
Add more metadata props to list and listItem (André Staltz)
depthordered, indexsource property optional in typescript definition (gRoberts84)Fix bug where rendering empty link references ([][]) would fail (Dennis S)
[][]) would fail (Dennis S)Fix bug where unwrapping certain disallowed nodes would fail (Petr Gazarov)
Add rawSourcePos property for passing structured source position info to renderers (Espen Hovlandsdal)
rawSourcePos property for passing structured source position info to
renderers (Espen Hovlandsdal)Pass properties of unknown nodes directly to renderer (Jesse Pinho)
Add support for fragment renderers (Benjamim Sonntag)
Fix language escaping in code blocks (Espen Hovlandsdal)
Pass the React key into an overridden text renderer (vanchagreen)
Allow overriding text renderer (Thibaud Courtoison)
Only use first language from code block (Espen Hovlandsdal)
Enable transformImageUri for image references (evoye)
Exclude babel config from npm package (Espen Hovlandsdal)
Your coding agent can read these notes before it upgrades. Set up the MCP server →