Let's say you are working on a Word Document.
You are using an ordered list. When you hit 'Enter' twice, the editor clears the last list line and add a new paragraph. That's what this plugin does.
yarn add slate-auto-exit-block
import AutoExitBlock from 'slate-auto-exit-block'
import { Editor } from 'slate-react'
// Add the plugin to your set of plugins...
const plugins = [
AutoExitBlock({
blockType: /^(h{1,6})$/,
exitBlockType: 'paragraph'
}),
AutoExitBlock({
blockType: 'blockquote',
exitBlockType: 'paragraph',
onEmptyBlock: true
}),
AutoExitBlock({
blockType: 'li',
exitBlockType: 'paragraph',
onEmptyBlock: true,
unwrap: true
})
]
// And later pass it into the Slate editor...
<Editor
...
plugins={plugins}
/>
Insert a new paragrah on simple Enter.
Insert a new paragraph on a double Enter if the last block is empty. Also removes this last block.
- Make it work for tables and other elements.