public void Save(TextWriter writer, MarkdownFormat format = null) { using (MarkdownWriter mw = MarkdownWriter.Create(writer, MarkdownWriterSettings.From(format))) { Save(mw); } }
public void Save(Stream stream, MarkdownFormat format = null) { using (MarkdownWriter mw = MarkdownWriter.Create(stream, MarkdownWriterSettings.From(format))) { Save(mw); } }
public MarkdownDocumentationWriter( DocumentationModel documentationModel, DocumentationUrlProvider urlProvider, DocumentationOptions options = null, DocumentationResources resources = null) : base(documentationModel, urlProvider, options, resources) { _writer = MarkdownWriter.Create(new StringBuilder()); }
public static void TestTableHeaderWithTwoCharacter() { using (MarkdownWriter mw = MarkdownWriter.Create(new StringBuilder())) { mw.WriteLine(); mw.WriteStartTable(3); mw.WriteStartTableRow(); mw.WriteStartTableCell(); mw.WriteString(" "); mw.WriteEndTableCell(); mw.WriteStartTableCell(); mw.WriteString("aa"); mw.WriteEndTableCell(); mw.WriteStartTableCell(); mw.WriteString("bb"); mw.WriteEndTableCell(); mw.WriteEndTableRow(); mw.WriteTableHeaderSeparator(); mw.WriteStartTableRow(); mw.WriteStartTableCell(); mw.WriteString(" "); mw.WriteEndTableCell(); mw.WriteStartTableCell(); mw.WriteString("c"); mw.WriteEndTableCell(); mw.WriteStartTableCell(); mw.WriteString("d"); mw.WriteEndTableCell(); mw.WriteEndTableRow(); mw.WriteEndTable(); Assert.Equal( @" | | aa | bb | | --- | --- | --- | | | c | d | ", mw.ToString()); } }
public static MarkdownWriter CreateBuilder(StringBuilder sb, MarkdownFormat format = null) { return(MarkdownWriter.Create(sb, settings: MarkdownWriterSettings.From(format))); }
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.Instance))) .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")); using (var sw = new StreamWriter(readmeFilePath, append: false, Encoding.UTF8)) using (MarkdownWriter mw = MarkdownWriter.Create(sw)) { mw.WriteHeading1("Orang Command-Line Interface"); mw.WriteString(application.Description); mw.WriteLine(); mw.WriteHeading2("Commands"); foreach (Command command in application.Commands) { mw.WriteStartBulletItem(); mw.WriteLink(command.Name, command.Name + "-command.md"); mw.WriteEndBulletItem(); } 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, "AllowedValues.md")); ImmutableArray <OptionValueProvider> providers = HelpProvider.GetProviders(commands).ToImmutableArray(); MDocument document = Document( Heading1("List of Allowed Values"), BulletList(providers.Select(f => Link(f.Name, "#" + f.Name .ToLower() .Replace("<", "") .Replace(">", "") .Replace("_", "-")))), providers.Select(provider => { return(new MObject[] { Heading2(provider.Name), Table( TableRow("Value", "Description"), provider.Values.Select(f => TableRow(f.HelpValue, f.Description))) }); })); 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); 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(); } }
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( "roslynator", "Roslynator Command-line Tool", 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\CommandLine.DocumentationGenerator\data"; } foreach (Command command in application.Commands) { string commandFilePath = Path.GetFullPath(Path.Combine(destinationDirectoryPath, $"{command.Name}-command.md")); using (var sw = new StreamWriter(commandFilePath, append: false, Encoding.UTF8)) using (MarkdownWriter mw = MarkdownWriter.Create(sw)) { var writer = new DocumentationWriter(mw); mw.WriteLine(); writer.WriteCommandHeading(command, application); writer.WriteCommandDescription(command); mw.WriteLink("Home", "README.md"); string additionalContentFilePath = Path.Combine(dataDirectoryPath, command.Name + "_bottom.md"); string additionalContent = (File.Exists(additionalContentFilePath)) ? File.ReadAllText(additionalContentFilePath) : ""; var sections = new List <string>() { "Synopsis", "Arguments", "Options" }; if (Regex.IsMatch(additionalContent, @"^\#+ Examples", RegexOptions.Multiline)) { sections.Add("Examples"); } foreach (string section in sections) { 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); if (!string.IsNullOrEmpty(additionalContent)) { mw.WriteLine(); mw.WriteLine(); mw.WriteRaw(additionalContent); } WriteFootNote(mw); Console.WriteLine(commandFilePath); } } Console.WriteLine("Done"); if (Debugger.IsAttached) { Console.ReadKey(); } }
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(); } }