private static XElement UniteSections(XText title, IEnumerable <XElement> sections, string namespaceName) { XElement result; List <XElement> actualSections = sections.Where(s => s != null).ToList(); switch (actualSections.Count) { case 0: throw new ArgumentOutOfRangeException($"Amount of {nameof(sections)}", 0, "Some sections expected."); case 1: result = actualSections.Single(); break; default: result = XDocumentHelpers.CreateElement("section", namespaceName); foreach (XElement currentSection in actualSections) { result.Add(currentSection); } break; } if (title != null) { XElement titleElement = CreateTitle(title, namespaceName); result.AddFirst(titleElement); } return(result); }
private static XElement CreateSection(XText title, IReadOnlyCollection <XElement> body, string namespaceName) { if ((title == null) && (body.Count == 0)) { return(null); } XElement section = XDocumentHelpers.CreateElement("section", namespaceName); if (title != null) { XElement titleElement = CreateTitle(title, namespaceName); section.Add(titleElement); } if (body.Count == 0) { XElement emptyLine = XDocumentHelpers.CreateElement("empty-line", namespaceName); section.Add(emptyLine); } else { section.Add(body); } return(section); }
private static XElement CreateTitle(XText title, string namespaceName) { XElement p = XDocumentHelpers.CreateElement("p", namespaceName, title); return(XDocumentHelpers.CreateElement("title", namespaceName, p)); }