Documentation

Create an inline format

Use mark() to add a format to part of a line. Select Yurich and click Highlight. The selected word is wrapped in <mark>.

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

const Highlight = mark({ name: 'highlight', tag: 'mark', shortcut: 'Mod+Shift+H' });

export function HighlightEditor() {
  const editor = useEditor({
    extensions: [Highlight],
    initialValue: "<p>Yurich deserves a little emphasis.</p>",
  });
  const active = useIsActive(editor, 'toggleHighlight');

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

Result

In the HTML returned by editor.getHTML(), only Yurich is wrapped in <mark>.

<p><mark>Yurich</mark> deserves a little emphasis.</p>

Below is the text node for Yurich in the document tree returned by editor.getJSON(). Its marks array contains highlight, the format name registered with mark().

{
  "type": "text",
  "text": "Yurich",
  "marks": [{ "type": "highlight" }]
}

Use lowercase tag names. The mark factory accepts an aliases list for equivalent input tags.

Verify an extension