Skip to content

Clear Formatting

ClearFormatting adds a toolbar button that removes all formatting marks (bold, italic, underline, strike, code, subscript, superscript, text color, font family, font size, highlight) from the current selection. Marks with isFormatting: false (like Link) are preserved. It uses the built-in unsetAllMarks command.

Not included in StarterKit. Add it separately.

Select some formatted text and click the clear formatting button to remove all formatting at once. Try selecting everything with Cmd/Ctrl+A to see all the formatting stripped in one click.

With the default theme. The toolbar shows the clear formatting button.

Click to try it out
import { Editor, Document, Paragraph, Text, Bold, Italic, ClearFormatting } from '@domternal/core';
import '@domternal/theme';
const editor = new Editor({
element: document.getElementById('editor')!,
extensions: [Document, Paragraph, Text, Bold, Italic, ClearFormatting],
content: '<p>Select <strong>bold</strong> or <em>italic</em> text and click the clear formatting button.</p>',
});

With the full theme and ToolbarController, ClearFormatting renders as a button with the icon in the utilities group.

ClearFormatting has no configurable options.

ClearFormatting does not register its own commands. The toolbar button calls the built-in unsetAllMarks command.

Removes all formatting marks from the current selection. Returns false if the selection is empty (collapsed cursor).

editor.commands.unsetAllMarks();

This command:

  1. Iterates through all mark types in the schema
  2. Skips marks where isFormatting: false (Link by default)
  3. Removes matching marks from every range in the selection
  4. Clears stored marks (prevents formatting from carrying to the next typed character)

ClearFormatting does not register any keyboard shortcuts.

ClearFormatting does not register any input rules.

ButtonIconGroupPriority
clearFormattingtextTSlashutilities200

The button calls unsetAllMarks when clicked. It has no active state or shortcut.

ClearFormatting is a minimal extension. Its only purpose is to register a toolbar button:

addToolbarItems(): ToolbarItem[] {
return [{
type: 'button',
name: 'clearFormatting',
command: 'unsetAllMarks',
icon: 'textTSlash',
label: 'Clear Formatting',
group: 'utilities',
priority: 200,
}];
}

The actual formatting removal logic lives in the built-in unsetAllMarks command (defined in markCommands.ts), which is available to all editors regardless of whether ClearFormatting is installed. ClearFormatting simply provides a convenient toolbar button for it.

MarkRemovedWhy
BoldYesisFormatting: true (default)
ItalicYesisFormatting: true (default)
UnderlineYesisFormatting: true (default)
StrikeYesisFormatting: true (default)
CodeYesisFormatting: true (default)
TextStyle (color, font, size, highlight)YesisFormatting: true (default)
SubscriptYesisFormatting: true (default)
SuperscriptYesisFormatting: true (default)
LinkNoisFormatting: false
import { ClearFormatting } from '@domternal/core';
ExportTypeDescription
ClearFormattingExtensionThe clear formatting extension

@domternal/core - ClearFormatting.ts