Skip to content

Commit a4b750b

Browse files
committed
doc: Update react-markdown v9 document.
1 parent d482049 commit a4b750b

File tree

1 file changed

+109
-36
lines changed

1 file changed

+109
-36
lines changed

core/README.md

Lines changed: 109 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ export default function Demo() {
418418
}
419419
```
420420

421-
### Options Props
421+
## Options Props
422422

423423
```typescript
424424
import { ReactMarkdownProps } from 'react-markdown';
@@ -445,58 +445,131 @@ type MarkdownPreviewProps = {
445445
- `className` (`string?`)\
446446
Wrap the markdown in a `div` with this class name
447447

448-
This [`ReactMarkdownProps`](https://github.com/remarkjs/react-markdown/tree/02bac837bf141cdb8face360fb88be6fa33ab194#props) details. [Upgrade `react-markdown` v6](https://github.com/remarkjs/react-markdown/blob/15b4757082cf3f32a25eba0b8ea30baf751a8b40/changelog.md#600---2021-04-15)
448+
This [`ReactMarkdownProps`](https://github.com/remarkjs/react-markdown/tree/02bac837bf141cdb8face360fb88be6fa33ab194#props) details. [Upgrade `react-markdown` v9](https://github.com/remarkjs/react-markdown/tree/a27d335fc5419db4a2811e7f589d6467218346de?tab=readme-ov-file#options)
449449

450450
- `children` (`string`, default: `''`)\
451451
Markdown to parse
452452
- `className` (`string?`)\
453453
Wrap the markdown in a `div` with this class name
454454
- `skipHtml` (`boolean`, default: ~~`false`~~ -> [`true`](https://github.com/uiwjs/react-markdown-preview/issues/205) )\
455455
Ignore HTML in Markdown completely
456-
- `sourcePos` (`boolean`, default: `false`)\
457-
Pass a prop to all components with a serialized position
458-
(`data-sourcepos="3:1-3:13"`)
459-
- `rawSourcePos` (`boolean`, default: `false`)\
460-
Pass a prop to all components with their [position][]
461-
(`sourcePosition: {start: {line: 3, column: 1}, end:…}`)
462-
- `includeElementIndex` (`boolean`, default: `false`)\
463-
Pass the `index` (number of elements before it) and `siblingCount` (number
464-
of elements in parent) as props to all components
465-
- `allowedElements` (`Array.<string>`, default: `undefined`)\
466-
Tag names to allow (can’t combine w/ `disallowedElements`).
467-
By default all elements are allowed
468-
- `disallowedElements` (`Array.<string>`, default: `undefined`)\
469-
Tag names to disallow (can’t combine w/ `allowedElements`).
470-
By default no elements are disallowed
471456
- `allowElement` (`(element, index, parent) => boolean?`, optional)\
472457
Function called to check if an element is allowed (when truthy) or not.
473458
`allowedElements` / `disallowedElements` is used first!
474-
- `unwrapDisallowed` (`boolean`, default: `false`)\
475-
Extract (unwrap) the children of not allowed elements.
476-
By default, when `strong` is not allowed, it and it’s children is dropped,
477-
but with `unwrapDisallowed` the element itself is dropped but the children
478-
used
479-
- `linkTarget` (`string` or `(href, children, title) => string`, optional)\
480-
Target to use on links (such as `_blank` for `<a target="_blank"…`)
481-
- `transformLinkUri` (`(href, children, title) => string`, default:
482-
[`./uri-transformer.js`](https://github.com/remarkjs/react-markdown/blob/02bac837bf141cdb8face360fb88be6fa33ab194/lib/uri-transformer.js), optional)\
483-
URL to use for links.
484-
The default allows only `http`, `https`, `mailto`, and `tel`, and is
485-
exported from this module as `uriTransformer`.
486-
Pass `null` to allow all URLs.
487-
See [security][]
488-
- `transformImageUri` (`(src, alt, title) => string`, default:
489-
[`./uri-transformer.js`](https://github.com/remarkjs/react-markdown/blob/02bac837bf141cdb8face360fb88be6fa33ab194/lib/uri-transformer.js), optional)\
490-
Same as `transformLinkUri` but for images
491-
- `components` (`Object.<string, Component>`, default: `{}`)\
492-
Object mapping tag names to React components
493459
- `remarkPlugins`<!--rehype:style=color: red;background-color: #ffeb3b;--> (`Array.<Plugin>`, default: `[]`)\
494460
List of [remark plugins](https://github.com/remarkjs/remark/blob/main/doc/plugins.md#list-of-plugins) to use.
495461
See the next section for examples on how to pass options
496462
- `rehypePlugins`<!--rehype:style=color: red;background-color: #ffeb3b;--> (`Array.<Plugin>`, default: `[]`)\
497463
List of [rehype plugins](https://github.com/rehypejs/rehype/blob/main/doc/plugins.md#list-of-plugins) to use.
498464
See the next section for examples on how to pass options
499465

466+
> [!NOTE]
467+
>
468+
> [Upgrade `react-markdown` ~~v8~~ to v9](https://github.com/remarkjs/react-markdown/blob/a27d335fc5419db4a2811e7f589d6467218346de/changelog.md?plain=1#L5-L144)
469+
470+
### Add `urlTransform`
471+
472+
The `transformImageUri` and `transformLinkUri` were removed.
473+
Having two functions is a bit much, particularly because there are more URLs
474+
you might want to change (or which might be unsafe so *we* make them safe).
475+
And their name and APIs were a bit weird.
476+
You can use the new `urlTransform` prop instead to change all your URLs.
477+
478+
### Remove `linkTarget`
479+
480+
The `linkTarget` option was removed; you should likely not set targets.
481+
If you want to, use
482+
[`rehype-external-links`](https://github.com/rehypejs/rehype-external-links).
483+
484+
### Remove `includeElementIndex`
485+
486+
The `includeElementIndex` option was removed, so `index` is never passed to
487+
components.
488+
Write a plugin to pass `index`:
489+
490+
<details>
491+
<summary>Show example of plugin</summary>
492+
493+
```jsx
494+
import {visit} from 'unist-util-visit'
495+
496+
function rehypePluginAddingIndex() {
497+
/**
498+
* @param {import('hast').Root} tree
499+
* @returns {undefined}
500+
*/
501+
return function (tree) {
502+
visit(tree, function (node, index) {
503+
if (node.type === 'element' && typeof index === 'number') {
504+
node.properties.index = index
505+
}
506+
})
507+
}
508+
}
509+
```
510+
511+
</details>
512+
513+
### Remove `rawSourcePos`
514+
515+
The `rawSourcePos` option was removed, so `sourcePos` is never passed to
516+
components.
517+
All components are passed `node`, so you can get `node.position` from them.
518+
519+
### Remove `sourcePos`
520+
521+
The `sourcePos` option was removed, so `data-sourcepos` is never passed to
522+
elements.
523+
Write a plugin to pass `index`:
524+
525+
<details>
526+
<summary>Show example of plugin</summary>
527+
528+
```jsx
529+
import {stringifyPosition} from 'unist-util-stringify-position'
530+
import {visit} from 'unist-util-visit'
531+
532+
function rehypePluginAddingIndex() {
533+
/**
534+
* @param {import('hast').Root} tree
535+
* @returns {undefined}
536+
*/
537+
return function (tree) {
538+
visit(tree, function (node) {
539+
if (node.type === 'element') {
540+
node.properties.dataSourcepos = stringifyPosition(node.position)
541+
}
542+
})
543+
}
544+
}
545+
```
546+
547+
</details>
548+
549+
### Remove extra props passed to certain components
550+
551+
When overwriting components, these props are no longer passed:
552+
553+
* `inline` on `code`
554+
— create a plugin or use `pre` for the block
555+
* `level` on `h1`, `h2`, `h3`, `h4`, `h5`, `h6`
556+
— check `node.tagName` instead
557+
* `checked` on `li`
558+
— check `task-list-item` class or check `props.children`
559+
* `index` on `li`
560+
— create a plugin
561+
* `ordered` on `li`
562+
— create a plugin or check the parent
563+
* `depth` on `ol`, `ul`
564+
— create a plugin
565+
* `ordered` on `ol`, `ul`
566+
— check `node.tagName` instead
567+
* `isHeader` on `td`, `th`
568+
— check `node.tagName` instead
569+
* `isHeader` on `tr`
570+
— create a plugin or check children
571+
572+
500573
## Markdown Features
501574

502575
### Supports for CSS Style

0 commit comments

Comments
 (0)