using System.Text; using Beam.Abstractions; using Beam.Models; namespace Beam.Exports { public class HtmlExporter : PlainTextExporter { public HtmlExporter(IDocument document, ArticleData? meta = null, Dictionary? linkButtons = null, string? eofHtml = null) : base(document) { Meta = meta; LinkButtons = linkButtons; EofHtml = eofHtml; } public ArticleData? Meta { get; } public Dictionary? LinkButtons { get; } public string? EofHtml { get; } protected override string Convert() { var text = Document.ToString(); // Convert newlines to

tags text = "

" + text.Replace("\n", "

") + "

"; if (Meta is null) return text; text = $"

{Meta.Name}

" + text; if (LinkButtons is null || LinkButtons.Count == 0) return text; StringBuilder buttons = new(); foreach(var (btnText, btnLink) in LinkButtons.Select((x) => (x.Key, x.Value))) { buttons.AppendLine($"{btnText}"); } var buttonsDiv = $"
{buttons}
"; text = buttonsDiv + text + buttonsDiv; text += EofHtml ?? ""; text = "\n" + text + ""; return text; } protected override Task ConvertAsync() { return Task.FromResult(Convert()); } } }