Help with rich text editor that supports lists and list items #4918
Unanswered
joseDaKing
asked this question in
Q&A
Replies: 1 comment
-
I have this working on production const Element = ({ attributes, children, element }) => {
const style = { textAlign: element.align };
switch (element.type) {
case 'bulleted-list':
return (
<ul style={style} {...attributes}>
{children}
</ul>
);
case 'heading-one':
return (
<h1 style={style} {...attributes}>
{children}
</h1>
);
case 'heading-two':
return (
<h2 style={style} {...attributes}>
{children}
</h2>
);
case 'list-item':
return (
<li style={style} {...attributes}>
{children}
</li>
);
case 'numbered-list':
return (
<ol style={style} {...attributes}>
{children}
</ol>
);
default:
return (
<p style={style} {...attributes}>
{children}
</p>
);
}
};
const renderElement = useCallback(props => <Element {...props} />, []);
<Slate editor={editor} value={value} onChange={onChange}>
<Toolbar />
<Editable
id={id}
name={name}
placeholder={placeholder}
renderElement={renderElement}
renderLeaf={renderLeaf}
spellCheck
onKeyDown={event => {
for (const hotkey in HOTKEYS) {
if (isHotkey(hotkey, event)) {
event.preventDefault();
const mark = HOTKEYS[hotkey];
toggleMark(editor, mark);
}
}
}}
/>
</Slate> Hope this helps, tell me if you need more help! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to create a simple RichTextEditor where you can have bold, italic, underline, strikethrough styles and it should also have support for simple ordered and unordered lists. So far I have added bold, italic, underline strikethrough styles but there are missing support for ordered and unordered lists.
I tried to follow the rich text editor example but had a hard time understanding toggleBlock function at line 68, please could someone explain what it actually does.
Here is my code:
Beta Was this translation helpful? Give feedback.
All reactions