@*
This file is part of NKK.
NKK is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
NKK is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.
You should have received a copy of the GNU Affero General Public License
along with NKK. If not, see .
*@
@using System.Text
@inject IHttpContextAccessor HttpContextAccessor
@if (StripOuter) {
@( (MarkupString)RenderHtml() )
} else {
@( (MarkupString)RenderHtml() )
}
@code {
[Parameter]
public RenderFragment? ChildContent { get; set; }
[Parameter]
public String? Content { get; set; }
[Parameter]
public FileInfo? File { get; set; }
[Parameter]
public bool UseTypographyStyle { get; set; } = true;
[Parameter]
public bool StripOuter { get; set; } = false;
[Parameter(CaptureUnmatchedValues = true)]
public Dictionary? ExtraAttributes { get; set; }
private String RenderHtml() {
if (ChildContent != null && Content != null && File != null)
throw new ArgumentException("Only one of Content, File, or ChildContent can be set.");
if (File != null)
Content = new StreamReader(File.FullName, Encoding.UTF8).ReadToEnd();
else if (ChildContent != null)
Content = ChildContent.RenderString();
var md = new MarkdownConverter(Content ?? String.Empty, new MarkdownOptions {
LocalLinkBase = HttpContextAccessor.HttpContext!.Request.Path
});
return md.ToHtml();
}
}