Documentation

Create a custom block

Use block() to format an entire paragraph. Put the caret inside the paragraph and click Callout. The paragraph becomes an <aside> block.

Live example
Example result
import { block, EditorContent, EditorProvider, useEditor, useIsActive } from 'yurich';

const Callout = block({ name: 'callout', tag: 'aside' });

export function CalloutEditor() {
  const editor = useEditor({
    extensions: [Callout],
    initialValue: "<p>The toolbar is yours to design.</p>",
  });
  const active = useIsActive(editor, 'toggleCallout');

  return (
    <EditorProvider editor={editor}>
      <button
        type="button"
        aria-pressed={active}
        onMouseDown={event => event.preventDefault()}
        onClick={() => editor.execute('toggleCallout')}
      >
        Callout
      </button>
      <EditorContent ariaLabel="Editor" />
    </EditorProvider>
  );
}

Result

In the HTML returned by editor.getHTML(), the whole paragraph is an <aside> block.

<aside>The toolbar is yours to design.</aside>

Below is the first block in the document returned by editor.getJSON(). Its type is callout, the name registered with block().

{
  "type": "callout",
  "content": [
    { "type": "text", "text": "The toolbar is yours to design." }
  ]
}

Verify an extension