Documentation

Inline code

Format a short code snippet in a paragraph.

Try it

Select “fetch()” and click Inline code. The document contains <p>Run <code>fetch()</code> for the next draft.</p>.

Live example
Example result

Add it to your editor

Enable Code for short code fragments inside a paragraph. Connect the control to toggleCode.

import { EditorContent, EditorProvider, Code, useEditor, useIsActive } from 'yurich';

export function CodeEditor() {
  const editor = useEditor({
    extensions: [Code],
    initialValue: "<p>Run fetch() for the next draft.</p>",
  });
  const active = useIsActive(editor, 'toggleCode');

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

Behavior to account for

This command formats a selection within a line. For a standalone snippet that preserves newlines, use the code block guide.

Features