using System.Net;
using System.Text;
///
/// Generates HTML for PubLeaflet content.
///
static class PubLeafletHtmlGenerator
{
public static string Generate(SiteStandard.Document document, PubLeaflet.Content content)
{
var html = new StringBuilder();
html.AppendLine("");
html.AppendLine("");
html.AppendLine("
");
html.AppendLine("");
html.AppendLine("");
html.AppendLine($"{WebUtility.HtmlEncode(document.Title)}");
if (document.Description is not null)
{
html.AppendLine($"");
}
html.AppendLine("");
html.AppendLine("");
html.AppendLine("");
html.AppendLine("");
html.AppendLine($"
{WebUtility.HtmlEncode(document.Title)}
");
html.AppendLine($"");
if (document.Tags is { Count: > 0 })
{
html.Append("
");
foreach (var tag in document.Tags)
{
html.Append($"{WebUtility.HtmlEncode(tag)} ");
}
html.AppendLine("
");
break;
case PubLeaflet.Blocks.Header header:
var level = Math.Clamp(header.Level ?? 1, 1, 6);
html.AppendLine($"{RenderLeafletRichText(header.Plaintext, header.Facets)}");
break;
case PubLeaflet.Blocks.Code code:
var langAttr = !string.IsNullOrEmpty(code.Language)
? $" class=\"language-{WebUtility.HtmlEncode(code.Language)}\""
: string.Empty;
html.AppendLine($"
{WebUtility.HtmlEncode(code.Plaintext)}
");
break;
case PubLeaflet.Blocks.Image image:
var altAttr = image.Alt is not null
? $" alt=\"{WebUtility.HtmlEncode(image.Alt)}\""
: " alt=\"\"";
html.AppendLine("");
html.AppendLine($"");
if (image.Alt is not null)
{
html.AppendLine($"{WebUtility.HtmlEncode(image.Alt)}");
}
html.AppendLine("");
break;
case PubLeaflet.Blocks.UnorderedList unorderedList:
RenderLeafletUnorderedList(html, unorderedList);
break;
case PubLeaflet.Blocks.Blockquote blockquote:
html.AppendLine("