editor.chain().focus().toggleBold().run()}>
B editor.chain().focus().toggleItalic().run()}>
ILink editor.chain().focus().toggleBulletList().run()}
>
• List
editor.chain().focus().toggleBlockquote().run()}
>
❝ Quote
);
}
// A rich text editor for a post body that stores markdown, so people can
// format without knowing it. The Markdown tab shows and edits the raw text.
// The markdown goes in a hidden field called `name`, so the surrounding form
// submits it as it would a textarea.
export default function PostEditor({name, value = '', id = 'post_body'}) {
const [markdown, setMarkdown] = useState(value);
const [tab, setTab] = useState('write');
const editor = useEditor({
extensions: [StarterKit, Markdown],
content: value,
contentType: 'markdown',
onUpdate: ({editor: e}) => setMarkdown(e.getMarkdown().trim()),
editorProps: {attributes: {class: 'post-editor-content', 'aria-label': 'Post body', role: 'textbox', 'aria-multiline': 'true'}},
});
const showTab = (next) => {
if (next === 'write' && editor) {
editor.commands.setContent(markdown, {contentType: 'markdown'});
}
setTab(next);
};
return (