기울임꼴
텍스트를 기울여 강조하거나 제목을 구분합니다.
직접 확인하기
“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로도 같은 명령이 실행됩니다. 불러온 HTML의 <i>는 <em>으로 정규화됩니다. 같은 글자에 있던 다른 서식은 유지할 수 있습니다.