protected virtual void RenderContent(CoconaHelpRenderingContext ctx, ICoconaHelpContent content) { switch (content) { case ICoconaHelpSectioningContent section: RenderSectioningContent(ctx, section); break; case HelpHeading heading: RenderHeading(ctx, heading); break; case HelpParagraph paragraph: RenderParagraph(ctx, paragraph); break; case HelpLabelDescriptionList labelDescriptionList: RenderLabelDescriptionList(ctx, labelDescriptionList); break; case HelpPreformattedText preformattedText: RenderPreformattedText(ctx, preformattedText); break; } }
public string Render(HelpMessage message) { var ctx = new CoconaHelpRenderingContext(); RenderContent(ctx, message); return(ctx.StringBuilder.ToString()); }
protected virtual void RenderParagraph(CoconaHelpRenderingContext ctx, HelpParagraph paragraph) { var depth = ctx.CurrentDepth - 1; ctx.StringBuilder .AppendPadding(depth) .AppendLine(paragraph.Content); }
protected virtual void RenderHeading(CoconaHelpRenderingContext ctx, HelpHeading heading) { var depth = ctx.CurrentDepth - 1; ctx.StringBuilder .AppendPadding(depth) .AppendLine(heading.Content); }
public SectionStackItem(CoconaHelpRenderingContext ctx, ICoconaHelpSectioningContent section) { _ctx = ctx; _ctx.Sections.Push(this); _ctx.CurrentSection = this; Section = section; ChildPosition = 0; }
protected virtual void RenderPreformattedText(CoconaHelpRenderingContext ctx, HelpPreformattedText pre) { var depth = ctx.CurrentDepth - 1; foreach (var line in pre.Content.Split('\n')) { ctx.StringBuilder .AppendPadding(depth) .AppendLine(line.TrimEnd()); } }
protected virtual void RenderLabelDescriptionList(CoconaHelpRenderingContext ctx, HelpLabelDescriptionList labelDescriptionList) { var depth = ctx.CurrentDepth - 1; var maxLabelLen = labelDescriptionList.Items.Max(x => x.Label.Length); foreach (var labelAndDesc in labelDescriptionList.Items) { ctx.StringBuilder .AppendPadding(depth) .Append(labelAndDesc.Label) .AppendPadding(maxLabelLen - labelAndDesc.Label.Length, " ") .Append(" ") .AppendLine(labelAndDesc.Description); } }
protected virtual void RenderSectioningContent(CoconaHelpRenderingContext ctx, ICoconaHelpSectioningContent section) { using (new CoconaHelpRenderingContext.SectionStackItem(ctx, section)) { var prevContentIsSection = false; foreach (var child in section.Children) { if (prevContentIsSection) { ctx.StringBuilder.AppendLine(); } RenderContent(ctx, child); ctx.CurrentSection !.Advance(); if (child is ICoconaHelpSectioningContent) { prevContentIsSection = true; } } } }