public void WriteCommandHeading(Command command, CommandLineApplication application) { _writer.WriteStartHeading(1); _writer.WriteInlineCode(application.Name + " " + command.Name); _writer.WriteEndHeading(); }
public override void WriteEndHeading() => _writer.WriteEndHeading();
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(); } }
public override void WriteTo(MarkdownWriter writer) { writer.WriteStartHeading(Level); WriteContentTo(writer); writer.WriteEndHeading(); }