# 斜体 {#italic}

Source: [为 React 编辑器添加斜体按钮 · Yurich](https://leeyujoo.com/yurich/zh-cn/features/italic/)

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

Package version: `0.1.2`

用斜体强调文字或区分标题。

## 试一试 {#try-it}

选中 “Yurich” 并点击 **斜体**。输出为 `<em>Yurich</em>`。

## 添加到编辑器 {#setup}

启用 `Italic` 并调用 `toggleItalic`。用 `onMouseDown` 保留选区。

```tsx
import { EditorContent, EditorProvider, Italic, useEditor, useIsActive } from 'yurich';

export function ItalicEditor() {
  const editor = useEditor({
    extensions: [Italic],
    initialValue: "<p>让 Yurich 稍微倾斜一下。</p>",
  });
  const active = useIsActive(editor, 'toggleItalic');

  return (
    <EditorProvider editor={editor}>
      <button
        type="button"
        aria-pressed={active}
        onMouseDown={event => event.preventDefault()}
        onClick={() => editor.execute('toggleItalic')}
      >
        斜体
      </button>
      <EditorContent ariaLabel="编辑器" />
    </EditorProvider>
  );
}
```

## 行为说明 {#behavior}

`Mod+I` 也能切换。输入的 `<i>` 会规范化为 `<em>`。

[功能](https://leeyujoo.com/yurich/zh-cn/features/)
