mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-03-29 15:31:37 +00:00
30 lines
932 B
C#
30 lines
932 B
C#
|
|
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);
|
||
|
|
}
|
||
|
|
}
|