/// <summary> /// Renders the content to a string. /// </summary> /// <param name="content">The content to render.</param> /// <returns>The list as an li HTML string.</returns> public string Render(IContent content) { var listItem = content as ListItem; var sb = new StringBuilder(); sb.Append($"<li>"); foreach (var subContent in listItem.Content) { if (_options.OmitParagraphTagsInsideListItems && subContent is Paragraph) { // Ignore paragraphs in list items var pContent = subContent as Paragraph; foreach (var pSubContent in pContent.Content) { var renderer = _rendererCollection.GetRendererForContent(pSubContent); sb.Append(renderer.Render(pSubContent)); } } else { var renderer = _rendererCollection.GetRendererForContent(subContent); sb.Append(renderer.Render(subContent)); } } sb.Append($"</li>"); return(sb.ToString()); }
/// <summary> /// Renders the content to a string. /// </summary> /// <param name="content">The content to render.</param> /// <returns>The html img or a tag.</returns> public string Render(IContent content) { var assetStructure = content as AssetStructure; var asset = assetStructure.Data.Target; var nodeType = assetStructure.NodeType; var sb = new StringBuilder(); if (nodeType != "asset-hyperlink" && asset.File?.ContentType != null && asset.File.ContentType.ToLower().Contains("image")) { sb.Append($"<img src=\"{asset.File.Url}\" alt=\"{asset.Title}\" />"); } else { sb.Append($"<a href=\"{asset.File.Url}\">"); if (assetStructure.Content != null && assetStructure.Content.Any()) { foreach (var subContent in assetStructure.Content) { var renderer = _rendererCollection.GetRendererForContent(subContent); sb.Append(renderer.Render(subContent)); } } else { sb.Append(asset.Title); } sb.Append("</a>"); } return(sb.ToString()); }
/// <summary> /// Renders a document to HTML. /// </summary> /// <param name="doc">The document to turn into HTML.</param> /// <returns>An HTML string.</returns> public async Task <string> ToHtml(Document doc) { var sb = new StringBuilder(); foreach (var content in doc.Content) { var renderer = _contentRendererCollection.GetRendererForContent(content); sb.Append(await renderer.RenderAsync(content)); } return(sb.ToString()); }
/// <summary> /// Renders the content to an html p-tag. /// </summary> /// <param name="content">The content to render.</param> /// <returns>The p-tag as a string.</returns> public string Render(IContent content) { var paragraph = content as Paragraph; var sb = new StringBuilder(); sb.Append("<p>"); foreach (var subContent in paragraph.Content) { var renderer = _rendererCollection.GetRendererForContent(subContent); sb.Append(renderer.Render(subContent)); } sb.Append("</p>"); return(sb.ToString()); }
/// <summary> /// Renders the content to an html td-tag. /// </summary> /// <param name="content">The content to render.</param> /// <returns>The table cell-tag as a string.</returns> public async Task <string> RenderAsync(IContent content) { var tableCell = content as TableCell; var sb = new StringBuilder(); sb.Append("<td>"); foreach (var subContent in tableCell.Content) { var renderer = _rendererCollection.GetRendererForContent(subContent); sb.Append(await renderer.RenderAsync(subContent)); } sb.Append("</td>"); return(sb.ToString()); }
/// <summary> /// Renders the content to a string. /// </summary> /// <param name="content">The content to render.</param> /// <returns>The a tag as a string.</returns> public string Render(IContent content) { var link = content as Hyperlink; var sb = new StringBuilder(); sb.Append($"<a href=\"{link.Data.Uri}\" title=\"{link.Data.Title}\">"); foreach (var subContent in link.Content) { var renderer = _rendererCollection.GetRendererForContent(subContent); sb.Append(renderer.Render(subContent)); } sb.Append("</a>"); return(sb.ToString()); }
/// <summary> /// Renders a document to HTML. /// </summary> /// <param name="doc">The document to turn into HTML.</param> /// <returns>An HTML string.</returns> public async Task <string> ToHtml(Document doc) { if (!(doc?.Content?.Any() ?? false)) { return(await Task.Run(() => "")); } var sb = new StringBuilder(); foreach (var content in doc.Content) { var renderer = _contentRendererCollection.GetRendererForContent(content); sb.Append(await renderer.RenderAsync(content)); } return(sb.ToString()); }
/// <summary> /// Renders the content to an html h-tag. /// </summary> /// <param name="content">The content to render.</param> /// <returns>The p-tag as a string.</returns> public string Render(IContent content) { var headingSize = 1; switch (content) { case Heading1 _: break; case Heading2 _: headingSize = 2; break; case Heading3 _: headingSize = 3; break; case Heading4 _: headingSize = 4; break; case Heading5 _: headingSize = 5; break; case Heading6 _: headingSize = 6; break; } var heading = content as IHeading; var sb = new StringBuilder(); sb.Append($"<h{headingSize}>"); foreach (var subContent in heading.Content) { var renderer = _rendererCollection.GetRendererForContent(subContent); sb.Append(renderer.Render(subContent)); } sb.Append($"</h{headingSize}>"); return(sb.ToString()); }
/// <summary> /// Renders the content to a string. /// </summary> /// <param name="content">The content to render.</param> /// <returns>The list as a quote HTML string.</returns> public string Render(IContent content) { var quote = content as Quote; var sb = new StringBuilder(); sb.Append($"<blockquote>"); foreach (var subContent in quote.Content) { var renderer = _rendererCollection.GetRendererForContent(subContent); sb.Append(renderer.Render(subContent)); } sb.Append($"</blockquote>"); return(sb.ToString()); }
/// <summary> /// Renders the content to a string. /// </summary> /// <param name="content">The content to render.</param> /// <returns>The list as an li HTML string.</returns> public string Render(IContent content) { var listItem = content as ListItem; var sb = new StringBuilder(); sb.Append($"<li>"); foreach (var subContent in listItem.Content) { var renderer = _rendererCollection.GetRendererForContent(subContent); sb.Append(renderer.Render(subContent)); } sb.Append($"</li>"); return(sb.ToString()); }
/// <summary> /// Renders the content to a string. /// </summary> /// <param name="content">The content to render.</param> /// <returns>The list as a ul or ol HTML string.</returns> public string Render(IContent content) { var list = content as List; var listTagType = "ul"; if (list.NodeType == "ordered-list") { listTagType = "ol"; } var sb = new StringBuilder(); sb.Append($"<{listTagType}>"); foreach (var subContent in list.Content) { var renderer = _rendererCollection.GetRendererForContent(subContent); sb.Append(renderer.Render(subContent)); } sb.Append($"</{listTagType}>"); return(sb.ToString()); }