ant-design-blazor/site/AntDesign.Docs/Highlight/PrismHighlighter.cs
2021-02-06 20:15:46 +08:00

28 lines
787 B
C#

using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace AntDesign.Docs.Highlight
{
public class PrismHighlighter : IPrismHighlighter
{
private readonly IJSRuntime jsRuntime;
public PrismHighlighter(IJSRuntime jsRuntime)
{
this.jsRuntime = jsRuntime;
}
public async ValueTask<MarkupString> HighlightAsync(string code, string language)
{
string highlighted = await jsRuntime.InvokeAsync<string>("AntDesign.Prism.highlight", code, language);
return new MarkupString(highlighted);
}
public async Task HighlightAllAsync()
{
await jsRuntime.InvokeVoidAsync("AntDesign.Prism.highlightAll");
}
}
}