protected override void Write(BlazorRenderer renderer, DefinitionList list) { renderer.OpenElement("dl"); renderer.WriteAttributes(list); foreach (var item in list) { var definitionItem = (DefinitionItem)item; for (int i = 0; i < definitionItem.Count; i++) { var definitionTermOrContent = definitionItem[i]; if (definitionTermOrContent is DefinitionTerm definitionTerm) { renderer.OpenElement("dt"); renderer.WriteAttributes(definitionTerm); renderer.WriteChildren(definitionTerm.Inline); renderer.CloseElement(); } else { renderer.OpenElement("dd"); renderer.WriteAttributes(definitionTermOrContent); renderer.Write(definitionTermOrContent); renderer.CloseElement(); } } } renderer.CloseElement(); }
protected override void Write(BlazorRenderer renderer, FooterBlock footer) { renderer.OpenElement("footer"); renderer.WriteAttributes(footer); renderer.WriteChildren(footer); renderer.CloseElement(); }
protected override void Write(BlazorRenderer renderer, FigureCaption caption) { renderer.OpenElement("figcaption"); renderer.WriteAttributes(caption); renderer.WriteChildren(caption.Inline); renderer.CloseElement(); }
protected override void Write(BlazorRenderer renderer, Figure figure) { renderer.OpenElement("figure"); renderer.WriteAttributes(figure); renderer.WriteChildren(figure); renderer.CloseElement(); }
protected override void Write(BlazorRenderer renderer, AutolinkInline autolink) { renderer.OpenElement("a"); renderer.AddAttribute("href", autolink.IsEmail ? $"mailto:{autolink.Url}" : autolink.Url); renderer.WriteAttributes(autolink); renderer.CloseElement(); }
protected override void Write(BlazorRenderer renderer, AbbreviationInline abbreviation) { renderer.OpenElement("abbr"); renderer.WriteAttribute("title", abbreviation.Abbreviation.Text); renderer.WriteAttributes(abbreviation); renderer.AddContent(abbreviation.Abbreviation.Label); renderer.CloseElement(); }
protected override void Write(BlazorRenderer renderer, MathInline math) { renderer.OpenElement("span"); renderer.WriteAttributes(math); renderer.AddContent("\\("); renderer.Write(math.Content); renderer.AddContent("\\)"); renderer.CloseElement(); }
protected override void Write(BlazorRenderer renderer, MathBlock math) { renderer.OpenElement("div"); renderer.WriteAttributes(math); renderer.AddContent("\\["); renderer.WriteLeafRawLines(math); renderer.AddContent("\\]"); renderer.CloseElement(); }
protected override void Write(BlazorRenderer renderer, LinkInline link) { var url = link.GetDynamicUrl != null?link.GetDynamicUrl() ?? link.Url : link.Url; if (link.IsImage) { renderer.OpenElement("img"); renderer.AddAttribute("src", url); } else { renderer.OpenElement("a"); renderer.AddAttribute("href", url); } if (!string.IsNullOrEmpty(link.Title)) { renderer.AddAttribute("title", link.Title); } renderer.WriteAttributes(link); renderer.WriteChildren(link); renderer.CloseElement(); }
protected override void Write(BlazorRenderer renderer, Table table) { renderer.OpenElement("table"); if (table.ColumnDefinitions.Any(cd => cd.Width > 0 && cd.Width < 1)) { foreach (var tableColumnDefinition in table.ColumnDefinitions) { var width = Math.Round(tableColumnDefinition.Width * 100) / 100; var widthValue = string.Format(CultureInfo.InvariantCulture, "{0:0.##}", width); renderer.OpenElement("col"); renderer.AddAttribute("style", $"style=\"width:{widthValue}%\""); renderer.CloseElement(); } } bool bodyWritten = false; bool headerWritten = false; foreach (var rowObj in table) { var row = (TableRow)rowObj; if (row.IsHeader) { if (!headerWritten) { renderer.OpenElement("thead"); headerWritten = true; } } else if (!bodyWritten) { if (headerWritten) { renderer.CloseElement(); } renderer.OpenElement("tbody"); bodyWritten = true; } renderer.OpenElement("tr"); renderer.WriteAttributes(row); for (int i = 0; i < row.Count; i++) { var cell = (TableCell)row[i]; renderer.OpenElement(row.IsHeader ? "th" : "td"); if (cell.ColumnSpan != 1) { renderer.AddAttribute("colspan", cell.ColumnSpan); } if (cell.RowSpan != 1) { renderer.AddAttribute("rowspan", cell.RowSpan); } if (table.ColumnDefinitions.Count > 0) { var columnIndex = cell.ColumnIndex < 0 || cell.ColumnIndex >= table.ColumnDefinitions.Count ? i : cell.ColumnIndex; columnIndex = columnIndex >= table.ColumnDefinitions.Count ? table.ColumnDefinitions.Count - 1 : columnIndex; var alignment = table.ColumnDefinitions[columnIndex].Alignment; if (alignment.HasValue) { switch (alignment) { case TableColumnAlign.Center: renderer.AddAttribute("style", "text-align:center;"); break; case TableColumnAlign.Left: renderer.AddAttribute("style", "text-align:left;"); break; case TableColumnAlign.Right: renderer.AddAttribute("style", "text-align:right;"); break; } } renderer.WriteAttributes(cell); renderer.Write(cell); } renderer.CloseElement(); } renderer.CloseElement(); } if (bodyWritten) { renderer.CloseElement(); } renderer.CloseElement(); }