BlazorCodemirror 1.0.5

dotnet add package BlazorCodemirror --version 1.0.5
                    
NuGet\Install-Package BlazorCodemirror -Version 1.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorCodemirror" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlazorCodemirror" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="BlazorCodemirror" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BlazorCodemirror --version 1.0.5
                    
#r "nuget: BlazorCodemirror, 1.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BlazorCodemirror@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BlazorCodemirror&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=BlazorCodemirror&version=1.0.5
                    
Install as a Cake Tool

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:
      auto auto height and grow once the contents exceed that height
      300px fixed height, a scroll bar will appear if the height is exceeded
  • Width
    • Component width,default value 100%.
    • options:
      100% fixed percent width
      300px fixed width
  • ReadOnly
    • default value false.
  • Mime
    • Editor mode,default value text/x-csharp.
  • ModeURL
    • User mode file directory,default value _content/BlazorCodemirror/js/%N.min.js
  • Theme
    • Codemirror theme,default value dracula

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 569 7/12/2023
1.0.4 252 7/11/2023
1.0.3 242 7/10/2023
1.0.2 291 7/10/2023 1.0.2 is deprecated because it is no longer maintained.
1.0.1 294 7/10/2023 1.0.1 is deprecated because it is no longer maintained.
1.0.0 309 7/10/2023 1.0.0 is deprecated because it is no longer maintained.

Add ReadOnly,Width parameters.
Change Height parameter to string type.