1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-26 16:44:22 +02:00

fix some doc's bug (with v0.57.1) (#3393)

* fix: code blocks's info string
this info string. should be `jsx`

* fix: editor's exec invoke
now, editor.exec() is not available in Slate v0.57.1
so, use editor.insertText() to instead it

*  refactor: delete a nerver used value

* update add new chinese translate
      update chinese translate to `v0.57.1`

Co-authored-by: Ian Storm Taylor <ian@ianstormtaylor.com>
This commit is contained in:
Xleine
2020-01-28 04:24:15 +08:00
committed by Ian Storm Taylor
parent 8202e08102
commit 217bdd611b
7 changed files with 28 additions and 38 deletions

View File

@@ -6,7 +6,7 @@ But that's not all you can do. Slate lets you define any type of custom blocks y
We'll show you how. Let's start with our app from earlier:
```js
```jsx
const App = () => {
const editor = useMemo(() => withReact(createEditor()), [])
const [value, setValue] = useState([
@@ -22,7 +22,7 @@ const App = () => {
onKeyDown={event => {
if (event.key === '&') {
event.preventDefault()
editor.exec({ type: 'insert_text', text: 'and' })
editor.insertText("and")
}
}}
/>
@@ -37,7 +37,7 @@ The problem is, code blocks won't just be rendered as a plain paragraph, they'll
Element renderers are just simple React components, like so:
```js
```jsx
// Define a React component renderer for our code blocks.
const CodeElement = props => {
return (
@@ -56,7 +56,7 @@ And see that `props.children` reference? Slate will automatically render all of
And here's a component for the "default" elements:
```js
```jsx
const DefaultElement = props => {
return <p {...props.attributes}>{props.children}</p>
}
@@ -64,7 +64,7 @@ const DefaultElement = props => {
Now, let's add that renderer to our `Editor`:
```js
```jsx
const App = () => {
const editor = useMemo(() => withReact(createEditor()), [])
const [value, setValue] = useState([
@@ -93,7 +93,7 @@ const App = () => {
onKeyDown={event => {
if (event.key === '&') {
event.preventDefault()
editor.exec({ type: 'insert_text', text: 'and' })
editor.insertText("and")
}
}}
/>
@@ -116,7 +116,7 @@ const DefaultElement = props => {
Okay, but now we'll need a way for the user to actually turn a block into a code block. So let's change our `onKeyDown` function to add a `` Ctrl-` `` shortcut that does just that:
```js
```jsx
// Import the `Editor` helpers from Slate.
import { Editor } from 'slate'
@@ -176,7 +176,7 @@ Now, if you press `` Ctrl-` `` the block your cursor is in should turn into a co
But we forgot one thing. When you hit `` Ctrl-` `` again, it should change the code block back into a paragraph. To do that, we'll need to add a bit of logic to change the type we set based on whether any of the currently selected blocks are already a code block:
```js
```jsx
const App = () => {
const editor = useMemo(() => withReact(createEditor()), [])
const [value, setValue] = useState([