# Features

Source: [React editor formatting and editing features · Yurich](https://leeyujoo.com/yurich/features/)

Package: [`yurich`](https://www.npmjs.com/package/yurich)

Package version: `0.1.2`

Paragraphs and line breaks work by default. Register extensions for the formats you need, such as bold, lists, and links. The same rules apply when you load, paste, or export content.

## Inline formatting

| Extension | Command | Shortcut |
| --- | --- | --- |
| [`Bold`](https://leeyujoo.com/yurich/features/bold/) | `toggleBold` | `Mod+B` |
| [`Italic`](https://leeyujoo.com/yurich/features/italic/) | `toggleItalic` | `Mod+I` |
| [`Underline`](https://leeyujoo.com/yurich/features/underline/) | `toggleUnderline` | `Mod+U` |
| [`Strikethrough`](https://leeyujoo.com/yurich/features/strikethrough/) | `toggleStrikethrough` | `Mod+Shift+S` |
| [`Code`](https://leeyujoo.com/yurich/features/code/) | `toggleCode` | |
| [`Link`](https://leeyujoo.com/yurich/features/link/) | `setLink`, `removeLink` | |

`Mod` is Command on macOS and Control on Windows and Linux. Inline toggles need a selection. A partially formatted selection becomes fully formatted when toggled.

Pass `{ href: 'https://example.com' }` to `editor.execute('setLink', value)`. With selected text, Yurich links the selection. At a caret, it inserts the URL as linked text. `removeLink` clears link formatting and can remove the whole link at a caret. Supported URL prefixes are `http://`, `https://`, and `mailto:`.

## Blocks and lists

| Extension | Command | Output |
| --- | --- | --- |
| [`Heading`](https://leeyujoo.com/yurich/features/heading/) | `setHeading` with a number from 1 to 6, `removeHeading` | Heading or paragraph |
| [`OrderedList`](https://leeyujoo.com/yurich/features/ordered-list/) | `toggleOrderedList` | Numbered list |
| [`UnorderedList`](https://leeyujoo.com/yurich/features/unordered-list/) | `toggleUnorderedList` | Bulleted list |
| [`Blockquote`](https://leeyujoo.com/yurich/features/blockquote/) | `toggleBlockquote` | Quote |
| [`CodeBlock`](https://leeyujoo.com/yurich/features/code-block/) | `toggleCodeBlock` | Preformatted block |

Block commands act on the selected blocks. List commands act on the selected items, splitting the surrounding list when necessary. Applying a heading, quote, or code block to a list item takes the item out of the list.

## Text alignment

Enable [`TextAlign`](https://leeyujoo.com/yurich/features/text-align/) and run `alignLeft`, `alignCenter`, `alignRight`, or `alignJustify`. The alignment is saved as `text-align` in HTML and as `attrs.textAlign` in JSON.

## Editing and history

[Undo and redo](https://leeyujoo.com/yurich/features/history/), [Paste and schema](https://leeyujoo.com/yurich/features/clipboard/), [IME composition](https://leeyujoo.com/yurich/features/ime/)

- The editor supports browser text input and pauses document normalization during IME composition.
- Pasted HTML is filtered by the enabled schema. Plain-text paste stays text. The editor disables dropping content.
- Use `editor.history.undo()` and `editor.history.redo()`, or `Mod+Z`, `Mod+Shift+Z`, and `Mod+Y`. Undo and redo restore the selection with the content.
- Use `useCanUndo(editor)` and `useCanRedo(editor)` to keep history buttons in sync.

## HTML and JSON

[HTML and JSON export](https://leeyujoo.com/yurich/features/html-and-json/)

- Read HTML with `editor.getHTML()` or observe it through `onChange`. Load HTML through `initialValue` or `editor.setHTML(html)`.
- Read structured output with `editor.getJSON()` or `onChangeJSON`. Treat the returned JSON as immutable. The public API loads HTML, and exports JSON for consumers that need structured output.
- Use `toHTML(element, extensions)` and `toJSON(element, extensions)` to serialize a DOM element with a specific set of extensions.

See [Save and restore HTML](https://leeyujoo.com/yurich/#save-and-restore-html) for a full example.

## React integration

[Reactive React state](https://leeyujoo.com/yurich/features/react-state/)

- Create the editor with `useEditor`, pass it to `EditorProvider`, and mount the editable area with `EditorContent`.
- Use `useEditorContext` for controls inside the provider and `useIsActive` for pressed states. `useEditorState` can subscribe to a value derived from the editor.
- Style the editable element via `className` and label it with `ariaLabel` or `ariaDescribedBy`.

Use [Custom extensions](https://leeyujoo.com/yurich/extensions/) to add formats, blocks, or commands to the schema. The [API reference](https://leeyujoo.com/yurich/api/) lists the full public signatures.
