Personal website
at master 56 lines 1.8 kB view raw
1@* 2 This file is part of NKK. 3 4 NKK is free software: you can redistribute it and/or modify it under the 5 terms of the GNU Affero General Public License as published by the Free 6 Software Foundation, either version 3 of the License, or (at your option) 7 any later version. 8 9 NKK is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 11 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for 12 more details. 13 14 You should have received a copy of the GNU Affero General Public License 15 along with NKK. If not, see <http://www.gnu.org/licenses/>. 16*@ 17 18@using System.Text 19@using Microsoft.PowerShell.MarkdownRender 20 21<div @attributes="ExtraAttributes" class="@( UseTypographyStyle == true ? "tx" : "" ) @( ExtraAttributes?["class"] )"> 22@* <div @attributes="ExtraAttributes" class="@( UseTypographyStyle == true ? "tx" : "" )"> *@ 23 @( (MarkupString)RenderHtml() ) 24</div> 25 26@code { 27 [Parameter] 28 public RenderFragment? ChildContent { get; set; } 29 30 [Parameter] 31 public String? Content { get; set; } 32 33 [Parameter] 34 public FileInfo? File { get; set; } 35 36 [Parameter] 37 public bool? UseTypographyStyle { get; set; } = true; 38 39 [Parameter(CaptureUnmatchedValues = true)] 40 public Dictionary<String, Object>? ExtraAttributes { get; set; } 41 42 private String RenderHtml() { 43 if (ChildContent != null && Content != null && File != null) { 44 throw new ArgumentException("Only one of Content, File, or ChildContent can be set."); 45 } 46 47 if (File != null) { 48 using StreamReader reader = new StreamReader(File.FullName, Encoding.UTF8); 49 Content = reader.ReadToEnd(); 50 } else if (ChildContent != null) { 51 Content = ChildContent.RenderString(); 52 } 53 54 return MarkdownConverter.Convert(Content ?? String.Empty, MarkdownConversionType.HTML, null).Html; 55 } 56}