public static string GenerateAssemblyReadme(string assemblyName) { Assembly assembly = Assembly.Load(new AssemblyName(assemblyName)); var doc = new MDocument(Heading1(assemblyName + " API")); foreach (IGrouping <string, TypeInfo> grouping in assembly .DefinedTypes .Where(f => f.IsPublic) .GroupBy(f => f.Namespace) .OrderBy(f => f.Key)) { doc.Add(Heading2("Namespace " + grouping.Key)); AddHeadingWithTypes(doc, "Static Classes", grouping.Where(f => f.IsClass && f.IsStatic())); AddHeadingWithTypes(doc, "Classes", grouping.Where(f => f.IsClass && !f.IsStatic())); AddHeadingWithTypes(doc, "Structs", grouping.Where(f => f.IsValueType)); AddHeadingWithTypes(doc, "Interfaces", grouping.Where(f => f.IsInterface)); } doc.AddFootnote(); return(doc.ToString()); void AddHeadingWithTypes(MContainer parent, string name, IEnumerable <TypeInfo> types) { if (types.Any()) { parent.Add(Heading3(name), types .OrderBy(f => f.Name) .Select(f => BulletItem(f.Name))); } } }
private static string GetString(this MDocument document, bool addFootnote = true) { if (addFootnote) { document.Add(NewLine, Italic("(Generated with ", Link("DotMarkdown", "http://github.com/JosefPihrt/DotMarkdown"), ")")); } return(document.ToString(MarkdownFormat.Default.WithTableOptions(TableOptions.FormatHeader))); }
public static string GenerateProjectReadme( IEnumerable <SnippetGeneratorResult> results, MDocument document, ProjectReadmeSettings settings, bool addFootnote = true) { document.Add( (!string.IsNullOrEmpty(settings.Header)) ? Heading2(settings.Header) : null, BulletItem("Browse all available snippets with ", Link("Snippet Browser", GetSnippetBrowserUrl(settings.Environment.Kind)), "."), BulletItem("Download extension from ", Link("Marketplace", $"http://marketplace.visualstudio.com/search?term=publisher%3A\"Josef%20Pihrt\"%20{ProductName}&target={settings.Environment.Kind.GetIdentifier()}&sortBy=Name"), "."), Heading3("Snippets"), Table( TableRow("Group", "Count", TableColumn(HorizontalAlignment.Right)), results.OrderBy(f => f.DirectoryName).Select(f => { return(TableRow( Link(f.DirectoryName, $"{VisualStudioExtensionGitHubUrl}/{f.DirectoryName}/{ReadMeFileName}"), f.Snippets.Count, Link("Browse", GetSnippetBrowserUrl(settings.Environment.Kind, f.Language)))); }))); return(document.GetString(addFootnote: addFootnote)); }
private static void AddFootnote(this MDocument document) { document.Add(NewLine, Italic("(Generated with ", Link("DotMarkdown", "http://github.com/JosefPihrt/DotMarkdown"), ")")); }
public static string GenerateDirectoryReadme( IEnumerable <Snippet> snippets, MDocument document, DirectoryReadmeSettings settings) { document.Add((!string.IsNullOrEmpty(settings.Header)) ? Heading2(settings.Header) : null); if (!settings.IsDevelopment) { document.Add( Heading3("Snippet Browser"), BulletItem("Browse all available snippets with ", Link("Snippet Browser", GetSnippetBrowserUrl(settings.Environment.Kind, settings.Language)), ".")); } if (!settings.IsDevelopment && settings.AddQuickReference) { document.Add(GetQuickReference()); } document.Add(Heading3("List of Selected Snippets")); document.Add(Table( TableRow("Shortcut", "Title"), snippets .Where(f => !f.HasTag(KnownTags.ExcludeFromReadme)) .OrderBy(f => f.Shortcut) .ThenBy(f => f.GetTitle()) .Select(f => { return(TableRow( f.Shortcut, LinkOrText(f.GetTitle(), GetSnippetPath(f)))); }))); return(document.GetString()); IEnumerable <object> GetQuickReference() { List <ShortcutInfo> shortcuts = settings.Shortcuts .Where(f => f.Languages.Contains(settings.Language)) .ToList(); if (shortcuts.Count > 0) { yield return(Heading3("Quick Reference")); if (settings.QuickReferenceText != null) { yield return(Raw(settings.QuickReferenceText)); } if (settings.GroupShortcuts) { foreach (IGrouping <ShortcutKind, ShortcutInfo> grouping in shortcuts .GroupBy(f => f.Kind) .OrderBy(f => f.Key)) { string title = grouping.Key.GetTitle(); if (!string.IsNullOrEmpty(title)) { yield return(Heading4(title)); } yield return(TableWithShortcutInfoValueDesriptionComment(grouping)); } } else { yield return(NewLine); yield return(TableWithShortcutInfoValueDesriptionComment(shortcuts)); } } } string GetSnippetPath(Snippet snippet) { if (!settings.AddLinkToTitle) { return(null); } string _pattern = $"^{Regex.Escape(settings.DirectoryPath)}{Regex.Escape(Path.DirectorySeparatorChar.ToString())}?"; string path = Regex.Replace( snippet.FilePath, _pattern, "", RegexOptions.IgnoreCase); return(path.Replace('\\', '/')); } MTable TableWithShortcutInfoValueDesriptionComment(IEnumerable <ShortcutInfo> shortcuts) { return(Table( TableRow("Shortcut", "Description", "Comment"), shortcuts .OrderBy(f => f.Value) .ThenBy(f => f.Description) .Select(f => TableRow(f.Value, f.Description, f.Comment)))); } }
private static void Main(params string[] args) { IEnumerable <Command> commands = CommandLoader.LoadCommands(typeof(CommandLoader).Assembly) .Select(c => c.WithOptions(c.Options.OrderBy(f => f, CommandOptionComparer.Name))) .OrderBy(c => c.Name, StringComparer.InvariantCulture); var application = new CommandLineApplication( "orang", "Search, replace, rename and delete files and its content using the power of .NET regular expressions.", commands.OrderBy(f => f.Name, StringComparer.InvariantCulture)); string?destinationDirectoryPath = null; string?dataDirectoryPath = null; if (Debugger.IsAttached) { destinationDirectoryPath = (args.Length > 0) ? args[0] : @"..\..\..\..\..\docs\cli"; dataDirectoryPath = @"..\..\..\data"; } else { destinationDirectoryPath = args[0]; dataDirectoryPath = @"..\src\DocumentationGenerator\data"; } string readmeFilePath = Path.GetFullPath(Path.Combine(destinationDirectoryPath, "README.md")); var settings = new MarkdownWriterSettings( MarkdownFormat.Default.WithTableOptions( MarkdownFormat.Default.TableOptions | TableOptions.FormatHeaderAndContent)); using (var sw = new StreamWriter(readmeFilePath, append: false, Encoding.UTF8)) using (MarkdownWriter mw = MarkdownWriter.Create(sw, settings)) { mw.WriteStartHeading(1); mw.WriteString("Orang Command-Line Interface"); mw.WriteRaw(" <img align=\"left\" src=\"../../images/icon48.png\">"); mw.WriteEndHeading(); mw.WriteString(application.Description); mw.WriteLine(); mw.WriteHeading2("Commands"); Table( TableRow("Command", "Description"), application .Commands .Select(f => TableRow(Link(f.Name, f.Name + "-command.md"), f.Description))) .WriteTo(mw); mw.WriteLine(); string readmeLinksFilePath = Path.Combine(dataDirectoryPath, "readme_bottom.md"); if (File.Exists(readmeLinksFilePath)) { mw.WriteRaw(File.ReadAllText(readmeLinksFilePath)); } WriteFootNote(mw); Console.WriteLine(readmeFilePath); } string valuesFilePath = Path.GetFullPath(Path.Combine(destinationDirectoryPath, "OptionValues.md")); ImmutableArray <OptionValueProvider> providers = OptionValueProvider.GetProviders( commands.SelectMany(f => f.Options), OptionValueProviders.ProvidersByName.Select(f => f.Value)) .ToImmutableArray(); MDocument document = Document( Heading1("List of Option Values"), BulletList(providers.Select(f => Link( f.Name, MarkdownHelpers.CreateGitHubHeadingLink(f.Name)))), providers.Select(provider => { return(new MObject[] { Heading2(provider.Name), Table( TableRow("Value", " ", "Description"), provider.Values.Select(f => CreateTableRow(f, providers))) }); })); document.Add( Heading2("Expression Syntax"), Table( TableRow("Expression", "Description"), HelpProvider.GetExpressionItems(includeDate: true) .Select(f => TableRow(InlineCode(f.expression), f.description)))); AddFootnote(document); var markdownFormat = new MarkdownFormat( tableOptions: MarkdownFormat.Default.TableOptions | TableOptions.FormatContent); File.WriteAllText(valuesFilePath, document.ToString(markdownFormat)); foreach (Command command in application.Commands) { readmeFilePath = Path.GetFullPath(Path.Combine(destinationDirectoryPath, $"{command.Name}-command.md")); using (var sw = new StreamWriter(readmeFilePath, append: false, Encoding.UTF8)) using (MarkdownWriter mw = MarkdownWriter.Create(sw)) { var writer = new DocumentationWriter(mw); writer.WriteCommandHeading(command, application); writer.WriteCommandDescription(command); mw.WriteLink("Home", "README.md#readme"); foreach (string section in new[] { "Synopsis", "Arguments", "Options", "Samples" }) { mw.WriteString(" "); mw.WriteCharEntity((char)0x2022); mw.WriteString(" "); mw.WriteLink(section, "#" + section); } mw.WriteLine(); writer.WriteCommandSynopsis(command, application); writer.WriteArguments(command.Arguments); writer.WriteOptions(command.Options); string samplesFilePath = Path.Combine(dataDirectoryPath, command.Name + "_bottom.md"); if (File.Exists(samplesFilePath)) { string content = File.ReadAllText(samplesFilePath); mw.WriteRaw(content); } WriteFootNote(mw); Console.WriteLine(readmeFilePath); } } Console.WriteLine("Done"); if (Debugger.IsAttached) { Console.ReadKey(); } }