Skip to content

Commit 4346276

Browse files
committed
Remove support for passing custom props to components
Previously, this project automatically passed different extra props to particular components. Those props are sometimes useful to some people, but not always useful to everyone. When overwriting components, these props are no longer passed: * `inline` on `code`: — create a plugin or use `pre` for the block * `level` on `h1`, `h2`, `h3`, `h4`, `h5`, `h6` — check `node.tagName` instead * `checked` on `li` — check `task-list-item` class or check `props.children` * `index` on `li` — create a plugin * `ordered` on `li` — create a plugin or check the parent * `depth` on `ol`, `ul` — create a plugin * `ordered` on `ol`, `ul` — check `node.tagName` instead * `isHeader` on `td`, `th` — check `node.tagName` instead * `isHeader` on `tr` — create a plugin or check children When using options, these props are no longer passed: * `includeElementIndex`: `index` (create a plugin) * `rawSourcePos`: `sourcePosition` (use `node.position`) * `sourcePos`: `data-sourcepos` (create a plugin)
1 parent 8aabf74 commit 4346276

10 files changed

+449
-906
lines changed

changelog.md

+99
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,105 @@
22

33
All notable changes will be documented in this file.
44

5+
## 9.0.0 - unreleased
6+
7+
### Remove `includeElementIndex` option
8+
9+
The `includeElementIndex` option was removed, so `index` is never passed to
10+
components.
11+
Write a plugin to pass `index`:
12+
13+
<details>
14+
<summary>Show example of plugin</summary>
15+
16+
```jsx
17+
import {visit} from 'unist-util-visit'
18+
19+
function rehypePluginAddingIndex() {
20+
/**
21+
* @param {import('hast').Root} tree
22+
* @returns {undefined}
23+
*/
24+
return function (tree) {
25+
visit(tree, function (node, index) {
26+
if (node.type === 'element' && typeof index === 'number') {
27+
node.properties === index
28+
}
29+
})
30+
}
31+
}
32+
```
33+
34+
### Remove `rawSourcePos` option
35+
36+
The `rawSourcePos` option was removed, so `sourcePos` is never passed to
37+
components.
38+
All components are passed `node`, so you can get `node.position` from them.
39+
40+
### Remove `sourcePos` option
41+
42+
The `sourcePos` option was removed, so `data-sourcepos` is never passed to
43+
elements.
44+
Write a plugin to pass `index`:
45+
46+
<details>
47+
<summary>Show example of plugin</summary>
48+
49+
```jsx
50+
import {stringifyPosition} from 'unist-util-stringify-position'
51+
import {visit} from 'unist-util-visit'
52+
53+
function rehypePluginAddingIndex() {
54+
/**
55+
* @param {import('hast').Root} tree
56+
* @returns {undefined}
57+
*/
58+
return function (tree) {
59+
visit(tree, function (node) {
60+
if (node.type === 'element') {
61+
node.properties.dataSourcepos = stringifyPosition(node.position)
62+
}
63+
})
64+
}
65+
}
66+
```
67+
68+
### Remove extra props passed to certain components
69+
70+
When overwriting components, these props are no longer passed:
71+
72+
* `inline` on `code`:
73+
— create a plugin or use `pre` for the block
74+
* `level` on `h1`, `h2`, `h3`, `h4`, `h5`, `h6`
75+
— check `node.tagName` instead
76+
* `checked` on `li`
77+
— check `task-list-item` class or check `props.children`
78+
* `index` on `li`
79+
— create a plugin
80+
* `ordered` on `li`
81+
— create a plugin or check the parent
82+
* `depth` on `ol`, `ul`
83+
— create a plugin
84+
* `ordered` on `ol`, `ul`
85+
— check `node.tagName` instead
86+
* `isHeader` on `td`, `th`
87+
— check `node.tagName` instead
88+
* `isHeader` on `tr`
89+
— create a plugin or check children
90+
91+
## 8.0.7 - 2023-04-12
92+
93+
* [`c289176`](https://github.com/remarkjs/react-markdown/commit/c289176)
94+
Fix performance for keys
95+
by [**@wooorm**](https://github.com/wooorm)
96+
in [#738](https://github.com/remarkjs/react-markdown/pull/738)
97+
* [`9034dbd`](https://github.com/remarkjs/react-markdown/commit/9034dbd)
98+
Fix types in syntax highlight example
99+
by [**@dlqqq**](https://github.com/dlqqq)
100+
in [#736](https://github.com/remarkjs/react-markdown/pull/736)
101+
102+
**Full Changelog**: <https://github.com/remarkjs/react-markdown/compare/8.0.6...8.0.7>
103+
5104
## 8.0.6 - 2023-03-20
6105

7106
* [`33ab015`](https://github.com/remarkjs/react-markdown/commit/33ab015)

index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/**
2-
* @typedef {import('./lib/react-markdown.js').Options} Options
3-
* @typedef {import('./lib/ast-to-react.js').Components} Components
2+
* @typedef {import('hast-util-to-jsx-runtime').Components} Components
3+
* @typedef {import('hast-util-to-jsx-runtime').ExtraProps} ExtraProps
4+
* @typedef {import('./lib/index.js').Options} Options
45
*/
56

6-
export {uriTransformer} from './lib/uri-transformer.js'
7-
8-
export {ReactMarkdown as default} from './lib/react-markdown.js'
7+
export {ReactMarkdown as default, uriTransformer} from './lib/index.js'

0 commit comments

Comments
 (0)