public void Visit(BoldText boldText) { var ret = boldText.HasChildren ? "\n" : ""; _output.Append($"{GetTab(tabCounter)}<b name=\"{boldText.Name}\">{boldText.Text}{ret}"); tabCounter++; VisitParts(boldText.Parts); tabCounter--; if (boldText.HasChildren) { _output.Append($"{GetTab(tabCounter)}</b>\n"); } else { _output.Append($"</b>\n"); } }
static void VisitorSample() { Document doc = new Document(); var boldText = new BoldText { Name = "foo name", Parts = new List <DocumentPart> { new Hyperlink { Text = "link test", Url = "www.test.com" }, } }; var plainText = new Paragraph { Parts = new List <DocumentPart> { new Hyperlink { Text = "link test", Url = "www.test.com" }, boldText } }; doc.AddDocument(plainText); doc.AddDocument(new BoldText { Text = "bojan" }); HtmlVisitor visitor = new HtmlVisitor(); doc.Accept(visitor); Console.WriteLine("Html:\n" + visitor.Output); }