AI-Studio/app/MindWork AI Studio/Chat/MathJaxBlock.razor.cs

30 lines
932 B
C#
Raw Normal View History

2026-03-21 17:50:28 +00:00
using Microsoft.AspNetCore.Components;
namespace AIStudio.Chat;
public partial class MathJaxBlock
{
private const string MATH_JAX_SCRIPT_ID = "mudblazor-markdown-mathjax";
[Parameter]
public string Value { get; init; } = string.Empty;
[Parameter]
public string Class { get; init; } = string.Empty;
[Inject]
private IJSRuntime JsRuntime { get; init; } = null!;
private string RootClass => string.IsNullOrWhiteSpace(this.Class)
? "chat-mathjax-block"
: $"chat-mathjax-block {this.Class}";
private string MathText => $"$${Environment.NewLine}{this.Value}{Environment.NewLine}$$";
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await this.JsRuntime.InvokeVoidAsync("appendMathJaxScript", MATH_JAX_SCRIPT_ID);
await this.JsRuntime.InvokeVoidAsync("refreshMathJaxScript");
await base.OnAfterRenderAsync(firstRender);
}
}