### Install Blazor CodeMirror 6 package
Source: https://context7.com/gaelj/blazorcodemirror6/llms.txt
Use the .NET CLI to add the library to your project.
```bash
dotnet add package GaelJ.BlazorCodeMirror6
```
--------------------------------
### Log message in JavaScript
Source: https://context7.com/gaelj/blazorcodemirror6/llms.txt
A basic example of executing JavaScript console output.
```javascript
console.log('Hello!');
```
--------------------------------
### Available Simple Commands
Source: https://context7.com/gaelj/blazorcodemirror6/llms.txt
All parameterless commands available via `CodeMirrorSimpleCommand`.
```APIDOC
## Available Simple Commands
All parameterless commands available via `CodeMirrorSimpleCommand`.
### Method
POST (simulated via component method calls)
### Endpoint
N/A (Component-based interaction)
### Parameters
No explicit parameters for simple commands.
### Request Example
```csharp
await editorRef.CommandDispatcher.Dispatch(CodeMirrorSimpleCommand.Undo);
await editorRef.CommandDispatcher.Dispatch(CodeMirrorSimpleCommand.Focus);
```
### Response
No direct HTTP response, but editor state changes.
### Command List
- **Markdown formatting**
- `ToggleMarkdownBold`
- `ToggleMarkdownItalic`
- `ToggleMarkdownStrikethrough`
- `ToggleMarkdownCode`
- `ToggleMarkdownCodeBlock`
- `ToggleMarkdownQuote`
- `IncreaseMarkdownHeadingLevel`
- `DecreaseMarkdownHeadingLevel`
- `ToggleMarkdownUnorderedList`
- `ToggleMarkdownOrderedList`
- `ToggleMarkdownTaskList`
- `InsertMarkdownHorizontalRule`
- **History**
- `Undo`
- `Redo`
- `UndoSelection`
- `RedoSelection`
- **Indentation**
- `IndentLess`
- `IndentMore`
- `IndentSelection`
- **Line operations**
- `CopyLineUp`
- `CopyLineDown`
- `SelectLine`
- `InsertBlankLine`
- **Comments**
- `ToggleComment`
- `ToggleBlockComment`
- `LineComment`
- `LineUncomment`
- `BlockComment`
- `BlockUncomment`
- **Clipboard**
- `Cut`
- `Copy`
- `Paste`
- **Misc**
- `Focus`
- `CursorMatchingBracket`
- `SimplifySelection`
- `DeleteTrailingWhitespace`
- `ScrollIntoView`
- `ClearLocalStorage`
- `RequestLinterRefresh`
```
--------------------------------
### Use Open Iconic standalone
Source: https://github.com/gaelj/blazorcodemirror6/blob/main/Examples.BlazorServer/wwwroot/css/open-iconic/README.md
Include the default stylesheet and use the data-glyph attribute.
```html
```
```html
```
--------------------------------
### Configure CodeMirrorSetup Options
Source: https://context7.com/gaelj/blazorcodemirror6/llms.txt
Define editor behavior and features using the CodeMirrorSetup object. These settings are immutable after the editor is initialized.
```csharp
private readonly CodeMirrorSetup Setup = new()
{
Id = "my-editor-1", // Unique identifier
HighlightSpecialChars = true, // Show whitespace, tabs, newlines
History = true, // Enable undo/redo
FoldGutter = true, // Code folding
AllowMultipleSelections = true, // Multiple cursors
IndentOnInput = true, // Auto-indent
SyntaxHighlighting = true, // Syntax colors
BracketMatching = true, // Highlight matching brackets
CloseBrackets = true, // Auto-close brackets
Autocompletion = true, // Enable autocomplete
RectangularSelection = true, // Alt+drag selection
CrossHairSelection = true, // Crosshair cursor
HighlightSelectionMatches = true, // Highlight same text
AllowMentions = true, // @mentions support
ScrollToStart = false, // Scroll to start on load
ScrollToEnd = true, // Scroll to end on load
FileIcon = "fa fa-file", // Icon CSS class
KrokiUrl = "https://kroki.io", // Diagram rendering server
BindMode = DocumentBindMode.OnDelayedInput, // When to sync value
DebugLogs = false, // Console logging
FocusOnCreation = true, // Auto-focus
IndentWithTab = true // Tab key behavior
};
```
--------------------------------
### Available Simple Commands
Source: https://context7.com/gaelj/blazorcodemirror6/llms.txt
A list of parameterless commands accessible through the CodeMirrorSimpleCommand enum for formatting, history, and line operations.
```csharp
// Markdown formatting
CodeMirrorSimpleCommand.ToggleMarkdownBold
CodeMirrorSimpleCommand.ToggleMarkdownItalic
CodeMirrorSimpleCommand.ToggleMarkdownStrikethrough
CodeMirrorSimpleCommand.ToggleMarkdownCode
CodeMirrorSimpleCommand.ToggleMarkdownCodeBlock
CodeMirrorSimpleCommand.ToggleMarkdownQuote
CodeMirrorSimpleCommand.IncreaseMarkdownHeadingLevel
CodeMirrorSimpleCommand.DecreaseMarkdownHeadingLevel
CodeMirrorSimpleCommand.ToggleMarkdownUnorderedList
CodeMirrorSimpleCommand.ToggleMarkdownOrderedList
CodeMirrorSimpleCommand.ToggleMarkdownTaskList
CodeMirrorSimpleCommand.InsertMarkdownHorizontalRule
// History
CodeMirrorSimpleCommand.Undo
CodeMirrorSimpleCommand.Redo
CodeMirrorSimpleCommand.UndoSelection
CodeMirrorSimpleCommand.RedoSelection
// Indentation
CodeMirrorSimpleCommand.IndentLess
CodeMirrorSimpleCommand.IndentMore
CodeMirrorSimpleCommand.IndentSelection
// Line operations
CodeMirrorSimpleCommand.CopyLineUp
CodeMirrorSimpleCommand.CopyLineDown
CodeMirrorSimpleCommand.SelectLine
CodeMirrorSimpleCommand.InsertBlankLine
// Comments
CodeMirrorSimpleCommand.ToggleComment
CodeMirrorSimpleCommand.ToggleBlockComment
CodeMirrorSimpleCommand.LineComment
CodeMirrorSimpleCommand.LineUncomment
CodeMirrorSimpleCommand.BlockComment
CodeMirrorSimpleCommand.BlockUncomment
// Clipboard
CodeMirrorSimpleCommand.Cut
CodeMirrorSimpleCommand.Copy
CodeMirrorSimpleCommand.Paste
// Misc
CodeMirrorSimpleCommand.Focus
CodeMirrorSimpleCommand.CursorMatchingBracket
CodeMirrorSimpleCommand.SimplifySelection
CodeMirrorSimpleCommand.DeleteTrailingWhitespace
CodeMirrorSimpleCommand.ScrollIntoView
CodeMirrorSimpleCommand.ClearLocalStorage
CodeMirrorSimpleCommand.RequestLinterRefresh
```
--------------------------------
### Integrate Open Iconic with Foundation
Source: https://github.com/gaelj/blazorcodemirror6/blob/main/Examples.BlazorServer/wwwroot/css/open-iconic/README.md
Include the Foundation stylesheet and use the icon class.
```html
```
```html
```
--------------------------------
### Available Themes
Source: https://context7.com/gaelj/blazorcodemirror6/llms.txt
Lists all available themes from `ThemeMirrorTheme`.
```APIDOC
## Available Themes
All available themes from `ThemeMirrorTheme`.
### Method
N/A (Theme selection is typically done during editor initialization or configuration)
### Endpoint
N/A
### Parameters
N/A
### Request Example
```csharp
// Example of setting a theme during initialization (conceptual)
var editorOptions = new EditorOptions
{
Theme = ThemeMirrorTheme.Dracula
};
await editorRef.InitializeAsync(options: editorOptions);
```
### Response
N/A
### Theme List
- **Basic themes**
- `Default`
- `OneDark`
- `Dracula`
- `Nord`
- `Monokai`
- **GitHub themes**
- `GithubDark`
- `GithubLight`
- **VS Code themes**
- `VSCode`
- **Material themes**
- `MaterialDark`
- `MaterialLight`
- **Tokyo Night variants**
- `TokyoNight`
- `TokyoNightDay`
- `TokyoNightStorm`
- **Solarized themes**
- `SolarizedDark`
- `SolarizedLight`
- **XCode themes**
- `XCodeDark`
- `XCodeLight`
- **Other themes**
- `Amy`
- `AyuLight`
- `Barf`
- `Bespin`
- `BirdsOfParadise`
- `Cobalt`
- `CoolGlow`
- `Eclipse`
- `Sublime`
- `Aura`
```
--------------------------------
### Implement basic code editor
Source: https://context7.com/gaelj/blazorcodemirror6/llms.txt
A simple editor instance with two-way binding and theme configuration.
```razor
@page "/editor"
Line count: @Text?.Split('\n').Length
@code { private string? Text = @"function greet(name) { console.log(`Hello, ${name}!`); } greet('World');"; } ``` -------------------------------- ### Configure Blazor CodeMirror 6 imports Source: https://context7.com/gaelj/blazorcodemirror6/llms.txt Add the necessary namespaces to your _Imports.razor file. ```csharp @using GaelJ.BlazorCodeMirror6 @using GaelJ.BlazorCodeMirror6.Commands @using GaelJ.BlazorCodeMirror6.Models ``` -------------------------------- ### Configure Multi-Language Support Source: https://context7.com/gaelj/blazorcodemirror6/llms.txt Switch languages dynamically or auto-detect them based on file extensions. ```razor @page "/multi-language"Active styles: @string.Join(", ", ActiveStyles)
@code { private CodeMirror6Wrapper editorRef = null!; private string? MarkdownText = @"# Welcome to Markdown Editor This is **bold** and this is *italic*. ``` -------------------------------- ### Command Dispatcher Reference Source: https://context7.com/gaelj/blazorcodemirror6/llms.txt Execute editor commands programmatically via component reference. ```APIDOC ## Command Dispatcher Reference Execute editor commands programmatically via component reference. ### Method POST (simulated via component method calls) ### Endpoint N/A (Component-based interaction) ### Parameters #### Request Body - **command** (CodeMirrorCommand) - Required - The command to execute. - **parameter** (any) - Optional - The parameter for the command, if applicable. ### Request Example ```csharp // Example for inserting text await editorRef.CommandDispatcher.Dispatch( CodeMirrorCommandOneParameter.InsertOrReplaceText, "Inserted content" ); // Example for a simple command await editorRef.CommandDispatcher.Dispatch(CodeMirrorSimpleCommand.Focus); ``` ### Response No direct HTTP response, but editor state changes. ``` -------------------------------- ### Available Editor Themes Source: https://context7.com/gaelj/blazorcodemirror6/llms.txt Reference for built-in themes available via the ThemeMirrorTheme enum. ```csharp // Basic themes ThemeMirrorTheme.Default ThemeMirrorTheme.OneDark ThemeMirrorTheme.Dracula ThemeMirrorTheme.Nord ThemeMirrorTheme.Monokai // GitHub themes ThemeMirrorTheme.GithubDark ThemeMirrorTheme.GithubLight // VS Code themes ThemeMirrorTheme.VSCode // Material themes ThemeMirrorTheme.MaterialDark ThemeMirrorTheme.MaterialLight // Tokyo Night variants ThemeMirrorTheme.TokyoNight ThemeMirrorTheme.TokyoNightDay ThemeMirrorTheme.TokyoNightStorm // Solarized themes ThemeMirrorTheme.SolarizedDark ThemeMirrorTheme.SolarizedLight // XCode themes ThemeMirrorTheme.XCodeDark ThemeMirrorTheme.XCodeLight // And many more: Amy, AyuLight, Barf, Bespin, BirdsOfParadise, // Cobalt, CoolGlow, Eclipse, Sublime, Aura, etc. ``` -------------------------------- ### Style SVG icons with CSS Source: https://github.com/gaelj/blazorcodemirror6/blob/main/Examples.BlazorServer/wwwroot/css/open-iconic/README.md Set dimensions and fill colors for SVG icons using CSS. ```css .icon { width: 16px; height: 16px; } ``` ```css .icon-account-login { fill: #f00; } ``` -------------------------------- ### Configure diff and merge view Source: https://context7.com/gaelj/blazorcodemirror6/llms.txt Enables a merge view interface to compare original and modified text with syntax highlighting. ```razor @page "/diff-view"Type @ to trigger mention autocomplete
@code { private string? Text = "Hello @"; private readonly CodeMirrorSetup setup = new() { AllowMentions = true, Autocompletion = true }; private Task