MintedTextEditor supports two levels of formatting: character formatting (applied to inline text runs) and paragraph formatting (applied to entire block-level elements).
Character formatting is represented by TextStyle, an immutable value type. All "with" methods return a new TextStyle rather than mutating in place.
The recommended way to apply character formatting is through FormattingEngine, which handles splitting and merging runs automatically.
// Get the engine from the editor
var fmt = editor.FormattingEngine;
// Toggle bold across the current selection
fmt.ToggleBold();
fmt.ToggleItalic();
fmt.ToggleUnderline();
fmt.ToggleStrikethrough();
fmt.ToggleSubscript();
fmt.ToggleSuperscript();fmt.SetFontFamily("Georgia");
fmt.SetFontSize(18f);
fmt.SetForegroundColor(new EditorColor(0xFFFF0000)); // red
fmt.SetBackgroundColor(new EditorColor(0x40FFFF00)); // semi-transparent yellow highlightFor undo-aware programmatic formatting:
var action = new ApplyStyleAction(doc, selectedRange, s => s
.WithBold(true)
.WithFontSize(14f));
undoManager.Push(action); // executes and records undoTextStyle style = fmt.GetStyleAtCaret();
bool isBold = style.IsBold;
string? family = style.FontFamily;Paragraph formatting is stored in ParagraphStyle on each Paragraph block.
var paragraphFmt = editor.ParagraphFormattingEngine;
paragraphFmt.SetAlignment(TextAlignment.Center);
paragraphFmt.SetAlignment(TextAlignment.Justify);Available values: Left · Center · Right · Justify
paragraphFmt.SetHeadingLevel(1); // H1
paragraphFmt.SetHeadingLevel(2); // H2
paragraphFmt.SetHeadingLevel(0); // body textparagraphFmt.ToggleBulletList();
paragraphFmt.ToggleNumberedList();
paragraphFmt.Indent();
paragraphFmt.Outdent();paragraphFmt.SetIndentLevel(2);
paragraphFmt.SetLineSpacing(1.5f);
paragraphFmt.SetSpaceBefore(8f);
paragraphFmt.SetSpaceAfter(8f);paragraphFmt.ToggleBlockQuote();paragraphFmt.SetDirection(TextDirection.RightToLeft);All formatting operations performed through FormattingEngine and ParagraphFormattingEngine are automatically pushed to the UndoManager.
editor.UndoManager.Undo();
editor.UndoManager.Redo();var doc = editor.Document;
var para = (Paragraph)doc.Blocks[0];
// Check inline runs
foreach (var inline in para.Inlines)
{
if (inline is TextRun run)
Console.WriteLine($"{run.Text}: bold={run.Style.IsBold}");
}
// Check paragraph style
Console.WriteLine(para.Style.Alignment);
Console.WriteLine(para.Style.HeadingLevel);