protected virtual MarkdownSection GenerateSummarySection([NotNull] ModuleInformation module) { string modulePrefixText; if (!module.HasPrefix) { modulePrefixText = "These commands have no prefix."; } else { var moduleAliasChains = module.GetAliasChains().ToList(); var compiledAliases = moduleAliasChains .Skip(1) .Select(a => new MarkdownInlineCode(a).Compile()) .Humanize("or"); var moduleExtraAliases = moduleAliasChains.Skip(1).Any() ? $"You can also use {compiledAliases} instead of `{module.GetNameChain(true)}`." : string.Empty; modulePrefixText = $"These commands are prefixed with `{module.GetNameChain(true)}`. {moduleExtraAliases}"; } var summarySection = new MarkdownSection("Summary", 2).AppendContent ( new MarkdownParagraph() .AppendLine(modulePrefixText) .AppendLine(module.Summary) ); return(summarySection); }
protected virtual MarkdownSection GenerateCommandsSection([NotNull] ModuleInformation module) { var moduleCommandsSection = new MarkdownSection("Commands", 2); var commandGroups = module.Commands.GroupBy(c => c.Name).ToList(); foreach (var commandGroup in commandGroups) { if (commandGroup != commandGroups.First()) { moduleCommandsSection.AppendContent(new MarkdownHorizontalRule()); } var commandOverloads = new MarkdownSection("Overloads", 4); foreach (var command in commandGroup) { commandOverloads.AppendContentRange(GenerateCommandOverloadContent(command)); } // Filter out commands without names (we use the module's name chain instead) var commandGroupName = commandGroup.Key.IsNullOrWhitespace() ? commandGroup.First().Module.GetNameChain(true) : commandGroup.Key; var commandSection = new MarkdownSection(commandGroupName, 3).AppendContent(commandOverloads); commandSection.Header.Title.Emphasis = Italic; moduleCommandsSection.AppendContent(commandSection); } return(moduleCommandsSection); }
private static List <MarkdownSection> SplitToSections(string content, IEnumerable <MatchDetail> yamlDetails) { MarkdownSection section = new MarkdownSection { Location = new Location { EndLocation = Coordinate.GetCoordinate(content) } }; List <MarkdownSection> sections = new List <MarkdownSection> { section }; foreach (var splitterDetail in yamlDetails) { var matchedSections = splitterDetail.MatchedSections; var splitterId = splitterDetail.Id; foreach (var matchedSection in matchedSections) { foreach (var location in matchedSection.Value.Locations) { sections = Split(sections, location, splitterId); } } } return(sections); }
protected virtual MarkdownSection GenerateCommandsSection([NotNull] ModuleInfo module) { var moduleCommandsSection = new MarkdownSection("Commands", 2); var commandGroups = module.Commands.GroupBy(c => c.Name).ToList(); foreach (var commandGroup in commandGroups) { if (commandGroup != commandGroups.First()) { moduleCommandsSection.AppendContent(new MarkdownHorizontalRule()); } var commandOverloads = new MarkdownSection("Overloads", 4); foreach (var command in commandGroup) { commandOverloads.AppendContentRange(GenerateCommandOverloadContent(command)); } var commandSection = new MarkdownSection(commandGroup.Key, 3).AppendContent(commandOverloads); commandSection.Header.Title.Emphasis = Italic; moduleCommandsSection.AppendContent(commandSection); } return(moduleCommandsSection); }
private MarkdownFile GenerateTableOfContents(DotNetDocumentationFile xmlDocumentation, DotNetQualifiedClassNameTreeNode node) { List <DotNetType> types = xmlDocumentation.Types.Where(t => t.Name.FullNamespace == node.Value).ToList(); List <DotNetDelegate> _delegates = xmlDocumentation.Delegates.Where(d => d.Name.FullNamespace == node.Value).ToList(); MarkdownFile markdown = new MarkdownFile(); string header = "Contents of " + node.Value.FullName; if (node.Parent != null) { header = String.Format("Contents of [{0}]({1}).{2}", node.Parent.Value.FullName, TableOfContentsFilename(node.Parent.Value), node.Value.LocalName); } MarkdownSection section = markdown.AddSection(header); if (node.Children.Count > 0) { MarkdownSection childNamespacesSection = section.AddSection("Namespaces"); foreach (DotNetQualifiedClassNameTreeNode child in node.Children) { section.AddInLine(new MarkdownInlineLink(MarkdownText.Bold(child.Value.FullName), TableOfContentsFilename(child.Value))); } } AddTableOfContentsSection(section, "Concrete Types", types.Where(t => t.Category == TypeCategory.Normal).ToList()); AddTableOfContentsSection(section, "Static Types", types.Where(t => t.Category == TypeCategory.Static).ToList()); AddTableOfContentsSection(section, "Abstract Types", types.Where(t => t.Category == TypeCategory.Abstract).ToList()); AddTableOfContentsSection(section, "Interfaces", types.Where(t => t.Category == TypeCategory.Interface).ToList()); AddTableOfContentsSection(section, "Enums", types.Where(t => t.Category == TypeCategory.Enum).ToList()); AddTableOfContentsSection(section, "Structs", types.Where(t => t.Category == TypeCategory.Struct).ToList()); AddTableOfContentsSection(section, "Delegates", _delegates); AddTableOfContentsSection(section, "Exceptions", types.Where(t => t.Category == TypeCategory.Exception).ToList()); return(markdown); }
public void MarkdownSection_ToMarkdown_SectionAfterZeroEndlines() { //arrange MarkdownSection section = new MarkdownSection("Header"); string previousText = "The quick brown fox"; //act string text = section.ToMarkdownString(previousText); //assert Assert.AreEqual("\n\n# Header\n\n", text); }
public void MarkdownSection_ToMarkdown_SectionAfterJustOneEndline() { //arrange MarkdownSection section = new MarkdownSection("Header"); string previousText = "\n"; //act string text = section.ToMarkdownString(previousText); //assert Assert.AreEqual("# Header\n\n", text); }
public void MarkdownSection_ToMarkdown_TextThenSection() { //arrange MarkdownSection sectionA = new MarkdownSection("A"); MarkdownText text = new MarkdownText("Text"); sectionA.Add(text); MarkdownSection sectionB = sectionA.AddSection("B"); //act string result = sectionA.ToMarkdownString(); //assert Assert.AreEqual("# A\n\nText\n\n## B\n\n", result); }
private static List <MarkdownSection> Split(MarkdownSection section, Location splitter, string splitterId) { var sections = new List <MarkdownSection>(); var sectionStart = section.Location.StartLocation; var sectionEnd = section.Location.EndLocation; var splitterStart = splitter.StartLocation; var splitterEnd = splitter.EndLocation; if (sectionEnd.CompareTo(splitterStart) <= 0 || sectionStart.CompareTo(splitterEnd) >= 0) { return new List <MarkdownSection> { section } } ; var firstStart = sectionStart; var secondEnd = sectionEnd; var firstEnd = splitterStart.CompareTo(sectionStart) > 0 ? splitterStart : sectionStart; var secondeStart = splitterEnd.CompareTo(sectionEnd) < 0 ? splitterEnd : sectionEnd; if (firstStart.CompareTo(firstEnd) < 0) { sections.Add( new MarkdownSection { Location = new Location { StartLocation = firstStart, EndLocation = firstEnd }, Id = section.Id }); } if (secondeStart.CompareTo(secondEnd) < 0) { sections.Add( new MarkdownSection { Location = new Location { StartLocation = secondeStart, EndLocation = secondEnd }, Id = splitterId }); } return(sections); }
private void AddTableOfContentsSection(MarkdownSection parent, string header, List <DotNetDelegate> _delegates) { if (_delegates.Count == 0) { return; } MarkdownSection section = parent.AddSection(header); foreach (DotNetDelegate _delegate in _delegates.OrderBy(t => t.Name.LocalName)) { section.AddInLine(new MarkdownInlineLink(MarkdownText.Bold(_delegate.Name.LocalName), FormatFilename(_delegate.Name.FullName + Ext.MD))); section.Add(ConvertDotNet.DotNetCommentGroupToMarkdown(_delegate.SummaryComments, _delegate)); section.Add(new MarkdownLine()); } }
private MarkdownSection BuildMasterSummary(DotNetDocumentationFile xmlDocumentation, DotNetQualifiedClassNameTreeNode node) { string header = (new MarkdownInlineLink(node.Value, TableOfContentsFilename(node.Value))).ToMarkdownString(null); MarkdownSection section = new MarkdownSection(header); List <DotNetType> types = xmlDocumentation.Types.Where(t => t.Name.FullNamespace == node.Value).ToList(); foreach (DotNetType type in types.OrderBy(t => t.Name)) { section.Add(new MarkdownLine(new MarkdownInlineLink(type.Name, FormatFilename(type.Name + Ext.MD)))); } List <DotNetDelegate> _delegates = xmlDocumentation.Delegates.Where(d => d.Name.FullNamespace == node.Value).ToList(); foreach (DotNetDelegate _delegate in _delegates.OrderBy(d => d.Name)) { section.Add(new MarkdownLine(new MarkdownInlineLink(_delegate.Name, FormatFilename(_delegate.Name + Ext.MD)))); } foreach (DotNetQualifiedClassNameTreeNode child in node.Children.OrderBy(c => c.Value)) { section.AddSection(BuildMasterSummary(xmlDocumentation, child)); } return(section); }
protected virtual MarkdownSection GenerateSubmodulesSection([NotNull] ModuleInformation module) { var submoduleSection = new MarkdownSection("Submodules", 2); var submoduleList = new MarkdownList { Type = ListType.Bullet }; submoduleSection.AppendContent(submoduleList); foreach (var submodule in module.Submodules) { submoduleList.AppendItem ( new MarkdownLink ( $"{submodule.GetNameChain().Replace(" ", "_")}.md", submodule.Name.Humanize() ) ); } return(submoduleSection); }
private void GenerateTableOfContents(DotNetDocumentationFile xmlDocumentation, string directory) { List <DotNetQualifiedClassName> _namespaces = new List <DotNetQualifiedClassName>(); foreach (DotNetType type in xmlDocumentation.Types) { _namespaces.Add(type.ClassName.FullClassNamespace); } foreach (DotNetDelegate _delegate in xmlDocumentation.Delegates) { _namespaces.Add(_delegate.MethodName.FullClassNamespace); } _namespaces = _namespaces.Distinct().ToList(); DotNetQualifiedClassNameTreeNode root = DotNetQualifiedClassNameTreeNode.Generate(_namespaces); GenerateAndSaveTableOfContents(xmlDocumentation, root, directory); //master table of contents MarkdownFile markdown = new MarkdownFile(); MarkdownSection section = markdown.AddSection("Table of Contents"); if (root.Value == null) { foreach (DotNetQualifiedClassNameTreeNode node in root.Children) { MarkdownSection subsection = BuildMasterSummary(xmlDocumentation, node); section.AddSection(subsection); } } else { MarkdownSection subsection = BuildMasterSummary(xmlDocumentation, root); section.AddSection(subsection); } Save(markdown, directory, "TableOfContents" + Ext.MD); }
public MarkdownPage AppendSection(MarkdownSection section) { _sections.Add(section); return(this); }