BlazorCodemirror 1.0.5
dotnet add package BlazorCodemirror --version 1.0.5
NuGet\Install-Package BlazorCodemirror -Version 1.0.5
<PackageReference Include="BlazorCodemirror" Version="1.0.5" />
<PackageVersion Include="BlazorCodemirror" Version="1.0.5" />
<PackageReference Include="BlazorCodemirror" />
paket add BlazorCodemirror --version 1.0.5
#r "nuget: BlazorCodemirror, 1.0.5"
#:package BlazorCodemirror@1.0.5
#addin nuget:?package=BlazorCodemirror&version=1.0.5
#tool nuget:?package=BlazorCodemirror&version=1.0.5
BlazorCodemirror
This is a code editor component for Blazor,based on Codemirror 5.65.13.
Component include c-like mode and dracula theme.
Base Usage
Add package from nuget
dotnet add package BlazorCodemirror
Add style link to index.html
<link href="_content/BlazorCodemirror/css/BlazorCodemirror.css" rel="stylesheet" />
<link href="_content/BlazorCodemirror/css/codemirror_5.65.13_theme_dracula.min.css" rel="stylesheet" />
Add service to Program.cs
builder.Services.AddBlazorCodeMirror();
Add BlazorCodemirror component in your code
<BlazorCodemirror.BlazorCodemirror></BlazorCodemirror.BlazorCodemirror>
Parameters
- Id
- Component id,if page contains more than one editor,use the id parameter opearate the editor.
- Height
- Component height,default value 300px.
- options:
autoauto height and grow once the contents exceed that height
300pxfixed height, a scroll bar will appear if the height is exceeded
- Width
- Component width,default value 100%.
- options:
100%fixed percent width
300pxfixed width
- ReadOnly
- default value false.
- Mime
- Editor mode,default value
text/x-csharp.
- Editor mode,default value
- ModeURL
- User mode file directory,default value
_content/BlazorCodemirror/js/%N.min.js
- User mode file directory,default value
- Theme
- Codemirror theme,default value
dracula
- Codemirror theme,default value
Change code mode
1.Download mode file. for example: javascript
2.Rename file to {modename}.min.js. for example: javascript.min.js
3.Move file to wwwroot/js
4.Add BlazorCodemirror section to your code
<BlazorCodemirror.BlazorCodemirror Mime="text/javascript" ModeURL="js/%N.min.js"></BlazorCodemirror.BlazorCodemirror>
Dynamic change code mode
1.Download mode file. for example: javascript
2.Rename file to {modename}.min.js. for example: javascript.min.js
3.Move file to wwwroot/js
4.Add BlazorCodemirror section in your code,Id parameter is required
<BlazorCodemirror.BlazorCodemirror Mime="text/javascript" ModeURL="js/%N.min.js" Id="editor_one"></BlazorCodemirror.BlazorCodemirror>
5.Add change mode button in your code
<button @onclick="ChangeMode">Change Mode</button>
6.inject service in your page
@inject BlazorCodemirrorJsInterop _codemirror
7.Add ChangeMode function
private async Task ChangeMode()
{
await _codemirror.SetEditorMode("editor_one", "text/x-csharp");
}
full code example
@page "/counter"
@using BlazorCodemirror;
@inject BlazorCodemirrorJsInterop _codemirror
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<button @onclick="ChangeMode">Change Mode</button>
<BlazorCodemirror.BlazorCodemirror @bind-Value="@editorvalue" ModeURL="js/%N.min.js" Mime="text/x-mysql" Id="editor_one"></BlazorCodemirror.BlazorCodemirror>
@code {
private string editorvalue { get; set; }
private async Task ChangeMode()
{
await _codemirror.SetEditorMode("editor_one", "text/x-csharp");
}
}
Change theme
1.Download theme file
2.Move file to wwwroot/css
3.Add style link to index.html
4.Set Theme parameter for example:
<BlazorCodemirror.BlazorCodemirror Mime="text/x-csharp" Theme="dracula" Height="300" ModeURL="_content/BlazorCodemirror/js/%N.min.js" @bind-Value="@data.Template"></BlazorCodemirror.BlazorCodemirror>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- BuildBundlerMinifier (>= 3.2.449)
- Microsoft.AspNetCore.Components.Web (>= 6.0.19)
-
net7.0
- BuildBundlerMinifier (>= 3.2.449)
- Microsoft.AspNetCore.Components.Web (>= 7.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Add ReadOnly,Width parameters.
Change Height parameter to string type.