AugusteVN.Razor.PrismJS 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package AugusteVN.Razor.PrismJS --version 1.0.1
NuGet\Install-Package AugusteVN.Razor.PrismJS -Version 1.0.1
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="AugusteVN.Razor.PrismJS" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AugusteVN.Razor.PrismJS --version 1.0.1
#r "nuget: AugusteVN.Razor.PrismJS, 1.0.1"
#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.
// Install AugusteVN.Razor.PrismJS as a Cake Addin
#addin nuget:?package=AugusteVN.Razor.PrismJS&version=1.0.1

// Install AugusteVN.Razor.PrismJS as a Cake Tool
#tool nuget:?package=AugusteVN.Razor.PrismJS&version=1.0.1

Prism.js in Razor

The Prism.js syntax highlighter for HTML code blocks, encapsulated in Razor components.

Razor Components

Encapsulating components can be implemented on Razor pages or components.

<IncludePrism /> uses the JSRuntime to import the prism.js script at first render of this component's lifecycle method OnAfterRender. And loads the prism.css link tag. I recommend to place this near the top of your Razor page or component.

<PrismHighlighter /> uses the JSRuntime to invoke Prism.highlightAll at first render of this component's lifecycle method OnAfterRender. I recommend to place this near the bottom of your Razor page or component, after the target code blocks and not before the <IncludePrism />.

Usage Example

<IncludePrism />

<div>
    @BlogPost.Body
</div>
    
<PrismHighlighter />

Extension Methods

To invoke importing prism.js using the JSRuntime or to invoke Prism.highlightAll yourself, I included 2 extension methods.

InvokeImportPrismJsAsync uses the JSRuntime to import the prism.js script.

InvokePrismHighlightAllAsync uses the JSRuntime to invoke Prism.highlightAll.

Usage Example

@inject IJSRuntime JsRuntime

<textarea @onblur="HandleOnChange"></textarea>

@code {
    private void HandleOnChange(FocusEventArgs e)
    {
        Task.Run(() => JsRuntime.InvokePrismHighlightAllAsync());
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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.1.7 128 4/7/2024
1.1.6 74 4/7/2024
1.1.5 75 4/7/2024
1.1.4 86 4/7/2024
1.1.3 72 4/6/2024
1.1.2 76 4/6/2024
1.0.4 204 11/18/2023
1.0.3 449 10/29/2023
1.0.2 70 10/29/2023
1.0.1 68 10/29/2023
1.0.0 70 10/29/2023

Updated README.md.