GetText()
{
string plainText = await _editor.GetText();
}
```
--------------------------------
### Immediate vs Deferred Updates
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/04-quick-start.md
Control how content updates are handled. Use `Immediate="true"` for real-time updates as the user types, or `Immediate="false"` (default) for deferred updates to reduce re-renders. This is useful for performance optimization.
```csharp
@page "/updates"
@using MudExRichTextEditor
Last content: @Content
@code {
private bool Immediate = false;
private string Content = "";
}
```
--------------------------------
### Pre-fill and Insert Content
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/04-quick-start.md
Demonstrates methods to pre-fill the editor with HTML content using `SetHtml` and insert HTML at the current cursor position using `InsertHtmlAsync`.
```csharp
@page "/prefill"
@using MudExRichTextEditor
Set Content
Insert at Cursor
@code {
private MudExRichTextEdit Editor;
private async Task SetContent()
{
await Editor.SetHtml("Welcome
This content is pre-filled
");
}
private async Task InsertText()
{
await Editor.InsertHtmlAsync("Inserted text
");
}
}
```
--------------------------------
### Instantiate QuillBetterTableModule with Theme
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/06-architecture.md
Instantiate QuillBetterTableModule by passing the current MudBlazor theme and dark mode status. This allows the module to use theme palette colors for table cells.
```csharp
var module = new QuillBetterTableModule(theme, isDarkMode);
// Uses theme palette colors for table cells
```
--------------------------------
### Editor with Presets
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/04-quick-start.md
Shows how to use pre-configured presets (Minimal, Standard, Full) for the MudExRichTextEdit component to quickly set up different feature sets.
```csharp
@page "/editor"
@using MudExRichTextEditor
@using MudExRichTextEditor.Types
@code {
private string Content = "";
}
```
--------------------------------
### Deferred vs. Immediate Content Updates
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/06-architecture.md
Compares the behavior of deferred updates (default, false) with immediate updates. Deferred updates fire OnBlur once, while immediate updates fire OnContentChanged per keystroke, impacting parent re-renders.
```text
Without Immediate: OnBlur fires once
With Immediate: OnContentChanged fires per keystroke
```
--------------------------------
### Define Get HTML Behavior
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/03-types-configuration.md
Determines the format returned when retrieving editor content. Options include InnerHtml, SemanticHtml, Text, and Content (Delta JSON).
```csharp
public enum GetHtmlBehavior
{
InnerHtml,
SemanticHtml,
Text,
Content
}
```
--------------------------------
### Use Preset Configuration
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/05-api-summary.md
Illustrates how to apply a pre-configured set of tools and modules to the MudExRichTextEdit component using QuillPresets.
```razor
```
--------------------------------
### API Summary
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/README.md
A quick reference API summary with condensed tables for the component class signature, parameter categorization, method summaries, and type definitions.
```APIDOC
## API Summary
### Description
This provides a condensed reference to the MudExRichTextEditor's API, including its class signature, parameters, methods, and types.
### Component Class Signature
- Overview of the `MudExRichTextEdit` component's signature.
### Parameter Categorization
- Grouped lists of component parameters.
### Method Summaries
- Brief descriptions of all available public methods.
### Type Definitions at a Glance
- Quick reference for key types and enums.
### Dependencies and Version Info
- Details on package dependencies and version compatibility.
```
--------------------------------
### Custom Tools and Handlers
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/01-core-component.md
Shows how to configure the MudExRichTextEditor with custom toolbar tools and default tool handlers. Includes a 'print' tool that outputs semantic HTML and a custom handler for 'custom-action' that logs text to the console.
```csharp
@code {
private MudExRichTextEdit Editor;
private string Content = "";
private QuillTool[] CustomTools => new[]
{
QuillTools.Bold(),
QuillTools.Italic(),
new CustomTool((_, _) => PrintContent(), "print", "Print content", group: 99)
};
private DefaultToolHandler[] Handlers => new[]
{
new DefaultToolHandler("custom-action", async (editor, args) =>
{
var text = await editor.GetText();
Console.WriteLine("Custom action: " + text);
})
};
private async Task PrintContent()
{
var html = await Editor.GetSemanticHTML();
Console.WriteLine(html);
}
}
```
--------------------------------
### Generate Cache Buster Query Parameter
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/06-architecture.md
Generates a cache buster query parameter using the assembly version for production or a random GUID for development. This ensures resources are not cached inappropriately.
```csharp
public static string CacheBuster =>
$"?c={AssemblyVersion}{(Debugger.IsAttached ? Guid.NewGuid().ToFormattedId() : "")}";
```
--------------------------------
### SetHtml(string html)
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/01-core-component.md
Sets the HTML content of the editor. It waits up to 10 seconds for initialization if called before the editor is ready.
```APIDOC
## SetHtml(string html)
### Description
Sets the HTML content of the editor. Waits up to 10 seconds for initialization if called before the editor is ready.
### Method
POST
### Endpoint
/api/editor/html
### Parameters
#### Request Body
- **html** (string) - Required - HTML content to set
### Returns
Task (HTML that was set)
### Throws
Attempts to set content even if initialization times out, but may return null or incomplete results
### Request Example
```csharp
await _editor.SetHtml("Pre-filled content
");
```
### Response Example
```html
Pre-filled content
```
```
--------------------------------
### Get Editor Content in Delta Format
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/01-core-component.md
Retrieves the editor content in Quill's Delta format, represented as a JSON string. This format precisely captures the document's content and formatting.
```csharp
public async Task GetContent()
{
string deltaJson = await _editor.GetContent();
// Returns: {"ops":[{"insert":"Hello "},{"insert":"world","attributes":{"bold":true}}]}
}
```
--------------------------------
### Get Semantic HTML Content
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/01-core-component.md
Retrieves semantically correct HTML using Quill's getSemanticHTML() method. This normalizes formatting to semantic equivalents for cleaner output. Use for more structured HTML.
```csharp
public async Task GetSemanticHTML()
{
string semanticHtml = await _editor.GetSemanticHTML();
// Returns cleaner, more semantic HTML than GetHtml()
}
```
--------------------------------
### Implement QuillImageCompressorModule for Image Compression
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/02-modules-extensibility.md
Automatically compresses images on insertion to reduce file sizes. Configure quality, dimensions, and image type for compression.
```csharp
public class QuillImageCompressorModule : QuillModule
{
public override string[] JsFiles => [$"./_content/MudExRichTextEditor/modules/quill.imageCompressor.min.js{MudExRichTextEdit.CacheBuster}"];
public override string JsConfigFunction => @"imageCompress: {
quality: 0.7,
maxWidth: 1000,
maxHeight: 1000,
imageType: 'image/jpeg',
debug: true,
}";
}
```
```cshtml
Modules="@new[] { new QuillImageCompressorModule() }"
```
--------------------------------
### Enable Image Resizing with QuillBlotFormatterModule
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/README.md
To enable image resizing in custom configurations, include the QuillBlotFormatterModule. This allows images inserted in the editor to be resized directly.
```csharp
@using MudExRichTextEditor.Extensibility
@code {
private IQuillModule[] _modules = [
new QuillBlotFormatterModule(),
// other modules...
];
}
```
--------------------------------
### Get Raw HTML Content
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/01-core-component.md
Retrieves the raw HTML content from the editor's root element. This includes all formatting but without semantic normalization. Use when precise HTML representation is needed.
```csharp
public async Task GetHtml()
{
string html = await _editor.GetHtml();
Console.WriteLine(html); // Bold text
}
```
--------------------------------
### Get Editor Content in Different Formats
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/01-core-component.md
Retrieve the editor's content using the GetValue method. Specify the desired format using the GetHtmlBehavior enum. Recommended for most use cases is SemanticHtml.
```csharp
string html = await _editor.GetValue(GetHtmlBehavior.SemanticHtml);
string text = await _editor.GetValue(GetHtmlBehavior.Text);
string delta = await _editor.GetValue(GetHtmlBehavior.Content);
```
--------------------------------
### Retrieve Editor Content with Specific Behavior
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/03-types-configuration.md
Gets the editor's content using a specified behavior. Useful for obtaining raw HTML, semantic HTML, plain text, or Delta JSON.
```csharp
string html = await editor.GetValue(GetHtmlBehavior.InnerHtml);
string semHtml = await editor.GetValue(GetHtmlBehavior.SemanticHtml);
string text = await editor.GetValue(GetHtmlBehavior.Text);
string delta = await editor.GetValue(GetHtmlBehavior.Content);
```
--------------------------------
### Set HTML with User Input
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/06-architecture.md
Demonstrates setting HTML content directly from user input without sanitization. It is recommended to sanitize HTML server-side if storing user-generated content.
```csharp
await editor.SetHtml(userInput); // ⚠️ No sanitization
```
--------------------------------
### Minimal Editor Configuration
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/03-types-configuration.md
Configures a MudExRichTextEdit with the Minimal preset, specifying height and theme.
```razor
```
--------------------------------
### AllModules
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/01-core-component.md
Provides a read-only enumerable of all active modules within the editor. This includes both explicitly set modules and recommended modules if configured.
```APIDOC
## AllModules
### Description
Read-only enumerable of all active modules. Combines explicitly set `Modules` with recommended modules if `AlwaysUseRecommendedModules` is true.
### Method
`AllModules` (Property)
### Parameters
None
### Request Example
```csharp
foreach (var module in _editor.AllModules)
{
Console.WriteLine(module.GetType().Name);
}
```
### Response
#### Success Response (200)
IEnumerable
#### Response Example
None provided.
```
--------------------------------
### Project Structure Overview
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/06-architecture.md
Illustrates the directory layout and key files within the MudExRichTextEditor project, highlighting the separation of concerns for components, extensibility, and types.
```tree
MudExRichTextEditor/
├── MudExRichTextEdit.razor.cs # Main component implementation
├── Extensibility/ # Extension interfaces and implementations
│ ├── IQuillModule.cs # Module interface
│ ├── QuillModule.cs # Module base class
│ ├── IQuillModule.cs # Plugin marker interface
│ ├── QuillBlotFormatterModule.cs # Image resizing module
│ ├── QuillImageCompressorModule.cs # Image compression module
│ ├── QuillTableBetterModule.cs # Table module
│ ├── QuillBetterTableModule.cs # Alternative table module
│ ├── QuillMentionModule.cs # Mention/autocomplete module
│ ├── IMention.cs # Mention data type
│ └── QuillModules.cs # Module registry
└── Types/ # Type definitions and enums
├── QuillTheme.cs # Theme enum
├── QuillDebugLevel.cs # Debug level enum
├── GetHtmlBehavior.cs # Output format enum
├── Tool.cs # Tool and CustomTool classes
├── DefaultToolHandler.cs # Handler for custom tools
└── QuillPresets.cs # Preset configurations
```
--------------------------------
### Custom Upload Handler for Rich Text Editor
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/04-quick-start.md
Implement a custom upload function to handle file uploads in the rich text editor. This example shows how to convert the uploaded file to a base64 data URL.
```csharp
@page "/upload"
@using MudExRichTextEditor
@using MudBlazor.Extensions.Core
@code {
private MudExRichTextEdit Editor;
private async Task HandleUpload(UploadableFile file)
{
// Example: Convert to base64 data URL
await file.EnsureDataLoadedAsync();
var base64 = Convert.ToBase64String(file.Data);
return $"data:{file.ContentType};base64,{base64}";
// Or upload to server
// using var content = new MultipartFormDataContent();
// content.Add(new StreamContent(new MemoryStream(file.Data)), "file", file.FileName);
// var response = await httpClient.PostAsync("/api/upload", content);
// return await response.Content.ReadAsStringAsync();
}
}
```
--------------------------------
### QuillTool Static Method
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/05-api-summary.md
Retrieves all standard toolbar tools available for the Quill editor.
```csharp
static All() → IEnumerable - All standard tools
```
--------------------------------
### Color Picker Tools for Rich Text Editor
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/04-quick-start.md
Add color picker tools for text color and background highlight to the rich text editor's toolbar. This example uses custom palettes for both text and background colors.
```csharp
@page "/colors"
@using MudExRichTextEditor
@using MudExRichTextEditor.Types
@code {
private QuillTool[] CustomTools => new[]
{
QuillTools.Bold(),
QuillTools.Italic(),
// Text color with custom palette
QuillTools.Color(colors: new[] { "#FF0000", "#00FF00", "#0000FF", "#FFFF00" }),
// Highlight with custom palette
QuillTools.Background(colors: new[] { "#FFFF00", "#FF00FF", "#00FFFF" }),
QuillTools.Link(),
QuillTools.Image()
};
}
```
--------------------------------
### File Attachment Flow
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/06-architecture.md
Outlines the process for attaching files, including opening the dialog, handling custom upload functions, converting data, and inserting HTML into the editor.
```text
AttachFilesAsync()
↓
Open MudEx dialog
↓
User selects files
↓
For each file:
├─ Check if CustomUploadFunc provided
│ └─ Call CustomUploadFunc → returns URL
├─ Else, call EnsureDataLoadedAsync()
│ └─ Convert to data URL
└─ Call InsertHtmlAsync() → insert into editor
```
--------------------------------
### Configure Module in Constructor
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/06-architecture.md
Configure custom modules and their options when initializing the Quill editor via the constructor. Ensure the module name matches the registration.
```csharp
new {
MyModule = new { option1 = value1 },
modules = {
myModule = new { option1 = value1 }
}
}
```
--------------------------------
### MudExRichTextEdit Component API
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/README.md
Provides a complete API reference for the main `MudExRichTextEdit` Blazor component. It details all Razor parameters with their types and defaults, public methods with full signatures and examples, properties, internal callbacks, and usage patterns.
```APIDOC
## MudExRichTextEdit Component API Reference
### Description
This section details the API for the `MudExRichTextEdit` Blazor component, covering its parameters, methods, properties, and callbacks.
### Parameters
- **[ParameterName]** (Type) - Default: [DefaultValue] - Description of the parameter.
- ... (All Razor parameters with types and defaults)
### Public Methods
- **[MethodName]([ParameterList])** ([ReturnType]) - Description of the method.
- Example: `await MudExRichTextEdit.SomeMethod(param1, param2);`
- ... (Public methods with full signatures and examples)
### Properties
- **[PropertyName]** (Type) - Description of the property.
- ...
### Internal Callbacks
- **[CallbackName]** (Signature) - Description of the callback.
- ...
### Usage Patterns
- Examples demonstrating common usage scenarios for the component.
```
--------------------------------
### Insert Tables in Rich Text Editor
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/04-quick-start.md
Demonstrates how to insert a table with a specified number of rows and columns into the rich text editor using the InsertTableAsync method.
```csharp
@page "/tables"
@using MudExRichTextEditor
@using MudExRichTextEditor.Types
Insert 3x3 Table
@code {
private MudExRichTextEdit Editor;
private async Task Insert3x3Table()
{
await Editor.InsertTableAsync(3, 3);
}
}
```
--------------------------------
### Basic Styling and Colors
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/04-quick-start.md
Customize the appearance of the rich text editor by setting background colors, border colors, and applying custom CSS classes. This snippet demonstrates how to integrate MudBlazor's color system and custom styles.
```csharp
@page "/styling"
@using MudExRichTextEditor
@using MudBlazor.Extensions.Core
@code {
private string Content = "";
}
```
--------------------------------
### QuillMentionModule Constructors and Properties
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/02-modules-extensibility.md
Defines the generic QuillMentionModule class, enabling mention/autocomplete functionality. It includes constructors for setting up suggestion retrieval and event handlers for user interactions with mentions.
```csharp
public class QuillMentionModule : QuillModule
{
public QuillMentionModule(Func>> getItemsFunc, char denotationChar, params char[] denotationChars)
public QuillMentionModule(Func>> getItemsFunc, char[] denotationChars)
public Func MentionClicked { get; set; }
public Func MentionHovered { get; set; }
public Func BeforeMentionSelect { get; set; }
public Func AfterMentionSelect { get; set; }
public Task[]> GetMentionsFromContentAsync()
}
```
--------------------------------
### Rich Text Editor with Preview Pane
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/07-advanced-usage.md
Display a MudExRichTextEdit component alongside a live preview pane. Changes made in the editor are immediately reflected in the preview, separated by a grid layout.
```csharp
@page "/editor-preview"
@using MudExRichTextEditor
@using MudExRichTextEditor.Types
Editor
Preview
@((MarkupString)Content)
@code {
private string Content = "";
}
```
--------------------------------
### AttachFilesAsync()
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/01-core-component.md
Opens a dialog to select and insert files from the available files list. Files can be uploaded as data URLs or using a custom upload function.
```APIDOC
## AttachFilesAsync()
### Description
Opens a dialog to select and insert files from the available files list. Files can be uploaded as data URLs or using a custom upload function.
### Method
POST
### Endpoint
/api/editor/attach-files
### Returns
Task
### Request Example
```csharp
// Open file picker dialog
await _editor.AttachFilesAsync();
```
```
--------------------------------
### Define CustomTool Array for Toolbar
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/03-types-configuration.md
Demonstrates how to assemble an array of QuillTool objects, including standard tools and custom-defined tools, for use in the MudExRichTextEditor toolbar.
```csharp
var customTools = new QuillTool[]
{
QuillTools.Bold(),
QuillTools.Italic(),
new CustomTool(
onClick: async (_, editor) => await PrintContent(),
icon: Icons.Material.Filled.Print,
tooltip: "Print content",
color: Color.Primary,
group: 99
),
new CustomTool(
onClick: async (_, editor) => await SaveDraft(),
icon: Icons.Material.Filled.Save,
tooltip: "Save as draft",
group: 99
)
};
```
--------------------------------
### Custom Color Options
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/03-types-configuration.md
Shows how to create QuillTool instances for text and background colors with custom color palettes. This enables users to select from a predefined set of colors.
```csharp
var tools = new[]
{
QuillTools.Color(colors: new[] { "#FF0000", "#00FF00", "#0000FF" }),
QuillTools.Background(colors: new[] { "#FFFF00", "#FF00FF" })
};
```
--------------------------------
### Implement QuillTableBetterModule for Advanced Table Features
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/02-modules-extensibility.md
Provides advanced table functionality including row/column manipulation, cell merging, and context menus. Requires the table tool to be added to the toolbar.
```csharp
public class QuillTableBetterModule : QuillModule
{
public override string[] JsFiles => ["https://cdn.jsdelivr.net/npm/quill-table-better@1/dist/quill-table-better.js"];
public override string[] CssFiles => [
"./_content/MudExRichTextEditor/css/quill.table.better.css",
"./_content/MudExRichTextEditor/css/quill.table.better.mudblazor.css"
];
}
```
```cshtml
```
--------------------------------
### Combine and Deduplicate Modules
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/06-architecture.md
Combines explicitly provided modules with recommended modules, ensuring that only one instance of each module type is loaded using DistinctBy.
```csharp
public IEnumerable AllModules =>
(Modules ?? Enumerable.Empty())
.Concat(AlwaysUseRecommendedModules ? QuillModules.RecommendedModules : [])
.DistinctBy(m => m.GetType());
```
--------------------------------
### Minimal Quill Preset Configuration
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/02-modules-extensibility.md
Configures the rich text editor for basic text formatting with minimal tools.
```razor
```
--------------------------------
### Set HTML Content
Source: https://github.com/fgilde/mudexrichtexteditor/blob/master/_autodocs/01-core-component.md
Sets the HTML content of the editor. It waits up to 10 seconds for initialization if called before the editor is ready. Be aware that it might return null or incomplete results if initialization times out.
```csharp
public async Task SetHtml(string html)
{
await _editor.SetHtml("Pre-filled content
");
}
```