Italic
The Italic mark applies italic formatting to text. It renders as <em> and parses <em>, <i>, and CSS font-style: italic. Included in StarterKit by default.
Live Playground
Section titled “Live Playground”Select text and apply italic with buttons, keyboard shortcut (Cmd+I / Ctrl+I), or type *text* to trigger the input rule.
With the default theme enabled. Click the I toolbar button or use Cmd+I / Ctrl+I.
Vanilla JS preview - Angular components produce the same output
Vanilla JS preview - React components produce the same output
Plain editor without the theme. The buttons above call toggleItalic(), setItalic(), and unsetItalic() directly.
Italic is included in StarterKit, so it works out of the box. To use it standalone:
import { Editor, Document, Paragraph, Text, Italic, defaultIcons } from '@domternal/core';import '@domternal/theme';
const editorEl = document.getElementById('editor')!;
// Toolbarconst toolbar = document.createElement('div');toolbar.className = 'dm-toolbar';toolbar.innerHTML = `<div class="dm-toolbar-group"> <button class="dm-toolbar-button" data-mark="italic">${defaultIcons.textItalic}</button></div>`;editorEl.before(toolbar);
// Editorconst editor = new Editor({ element: editorEl, extensions: [Document, Paragraph, Text, Italic], content: '<p>This is <em>italic</em> text.</p>',});
// Toggle italic on clicktoolbar.addEventListener('click', (e) => { const btn = (e.target as Element).closest<HTMLButtonElement>('[data-mark]'); if (btn) editor.chain().focus().toggleItalic().run();});import { Component, signal } from '@angular/core';import { DomternalEditorComponent, DomternalToolbarComponent } from '@domternal/angular';import { Editor, Document, Paragraph, Text, Italic } from '@domternal/core';
@Component({ selector: 'app-editor', imports: [DomternalEditorComponent, DomternalToolbarComponent], templateUrl: './editor.html',})export class EditorComponent { editor = signal<Editor | null>(null); extensions = [Document, Paragraph, Text, Italic]; content = '<p>This is <em>italic</em> text.</p>';}@if (editor(); as ed) { <domternal-toolbar [editor]="ed" />}<domternal-editor [extensions]="extensions" [content]="content" (editorCreated)="editor.set($event)"/>import { Domternal } from '@domternal/react';import { Document, Paragraph, Text, Italic } from '@domternal/core';
export default function Editor() { return ( <Domternal extensions={[Document, Paragraph, Text, Italic]} content="<p>This is <em>italic</em> text.</p>" > <Domternal.Toolbar /> <Domternal.Content /> </Domternal> );}import { Editor, Document, Paragraph, Text, Italic } from '@domternal/core';
const editor = new Editor({ element: document.getElementById('editor')!, extensions: [Document, Paragraph, Text, Italic], content: '<p>This is <em>italic</em> text.</p>',});
// Toggle italic programmaticallyeditor.chain().focus().toggleItalic().run();To disable Italic in StarterKit:
StarterKit.configure({ italic: false })Schema
Section titled “Schema”| Property | Value |
|---|---|
| ProseMirror name | italic |
| Type | Mark |
| HTML tag | <em> |
Parsing rules
Section titled “Parsing rules”Italic parses from multiple HTML sources for maximum compatibility:
| Source | Condition |
|---|---|
<em> | Always |
<i> | Unless font-style: normal (Google Docs compatibility) |
CSS font-style | Value is italic (case-insensitive) |
Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
HTMLAttributes | Record<string, unknown> | {} | Custom HTML attributes added to the rendered <em> element |
import { Italic } from '@domternal/core';
const CustomItalic = Italic.configure({ HTMLAttributes: { class: 'my-italic' },});Commands
Section titled “Commands”setItalic
Section titled “setItalic”Applies italic formatting to the current selection.
editor.commands.setItalic();unsetItalic
Section titled “unsetItalic”Removes italic formatting from the current selection.
editor.commands.unsetItalic();toggleItalic
Section titled “toggleItalic”Toggles italic formatting on the current selection. Applies italic if not active, removes it if active.
editor.commands.toggleItalic();
// With chainingeditor.chain().focus().toggleItalic().run();Keyboard shortcuts
Section titled “Keyboard shortcuts”| Key | Action |
|---|---|
Mod-I | Toggle italic (toggleItalic) |
Mod is Cmd on macOS and Ctrl on Windows/Linux.
Input rules
Section titled “Input rules”| Input | Result |
|---|---|
*text* | Wraps text in italic |
_text_ | Wraps text in italic |
Type the closing * or _ to trigger the conversion. The markers are removed and the text between them becomes italic.
Toolbar items
Section titled “Toolbar items”Italic registers a button in the toolbar with the name italic in group format at priority 190.
| Item | Type | Command | Icon | Shortcut | Active when |
|---|---|---|---|---|---|
| Italic | button | toggleItalic | textItalic | Mod-I | Italic mark is active on selection |
Exports
Section titled “Exports”import { Italic } from '@domternal/core';import type { ItalicOptions } from '@domternal/core';| Export | Type | Description |
|---|---|---|
Italic | Mark extension | The italic mark extension |
ItalicOptions | TypeScript type | Options for Italic.configure() |
Source
Section titled “Source”@domternal/core - Italic.ts