mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-24 16:02:55 +02:00
Change renderNode docs to renderBlock and renderInline (#3083)
This commit is contained in:
committed by
Ian Storm Taylor
parent
91c2cb4e9e
commit
88b7efa975
@@ -8,12 +8,12 @@ You can define these behaviors by passing `props` into the editor, or you can de
|
|||||||
|
|
||||||
## Nodes & Marks
|
## Nodes & Marks
|
||||||
|
|
||||||
Using custom components for the nodes and marks is the most common rendering need. Slate makes this easy to do, you just define a `renderNode` function.
|
Using custom components for the nodes and marks is the most common rendering need. Slate makes this easy to do. In case of nodes, you just define a function and pass it to the `renderBlock` or `renderInline` prop of `Editor` component.
|
||||||
|
|
||||||
The function is called with the node's props, including `props.node` which is the node itself. You can use these to determine what to render. For example, you can render nodes using simple HTML elements:
|
The function is called with the node's props, including `props.node` which is the node itself. You can use these to determine what to render. For example, you can render nodes using simple HTML elements:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function renderNode(props, editor, next) {
|
function renderBlock(props, editor, next) {
|
||||||
const { node, attributes, children } = props
|
const { node, attributes, children } = props
|
||||||
|
|
||||||
switch (node.type) {
|
switch (node.type) {
|
||||||
@@ -29,6 +29,16 @@ function renderNode(props, editor, next) {
|
|||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function renderInline(props, editor, next) {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
<Editor
|
||||||
|
renderBlock={renderBlock}
|
||||||
|
renderInline={renderInline}
|
||||||
|
...
|
||||||
|
/>
|
||||||
```
|
```
|
||||||
|
|
||||||
> 🤖 Be sure to mix in `props.attributes` and render `props.children` in your node components! The attributes are required for utilities like Slate's `findDOMNode`, and the children are the actual text content of your nodes.
|
> 🤖 Be sure to mix in `props.attributes` and render `props.children` in your node components! The attributes are required for utilities like Slate's `findDOMNode`, and the children are the actual text content of your nodes.
|
||||||
@@ -36,7 +46,7 @@ function renderNode(props, editor, next) {
|
|||||||
You don't have to use simple HTML elements, you can use your own custom React components too:
|
You don't have to use simple HTML elements, you can use your own custom React components too:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function renderNode(props, editor, next) {
|
function renderBlock(props, editor, next) {
|
||||||
switch (props.node.type) {
|
switch (props.node.type) {
|
||||||
case 'paragraph':
|
case 'paragraph':
|
||||||
return <ParagraphComponent {...props} />
|
return <ParagraphComponent {...props} />
|
||||||
@@ -50,12 +60,12 @@ function renderNode(props, editor, next) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
And you can just as easily put that `renderNode` logic into a plugin, and pass that plugin into your editor instead:
|
And you can just as easily put that `renderBlock` or `renderInline` logic into a plugin, and pass that plugin into your editor instead:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function SomeRenderingPlugin() {
|
function SomeRenderingPlugin() {
|
||||||
return {
|
return {
|
||||||
renderNode(props, editor, next) {
|
renderBlock(props, editor, next) {
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user