文档

斜体

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

试一试

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

交互示例
示例结果

添加到编辑器

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

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>
  );
}

行为说明

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

功能