コード例 #1
0
        public static string CreateRefactoringsMarkdown(IEnumerable <RefactoringDescriptor> refactorings, IComparer <string> comparer)
        {
            MDocument document = Document(
                Heading2("Roslynator Refactorings"),
                GetRefactorings());

            document.AddFootnote();

            return(document.ToString());

            IEnumerable <object> GetRefactorings()
            {
                foreach (RefactoringDescriptor refactoring in refactorings.OrderBy(f => f.Title, comparer))
                {
                    yield return(Heading4($"{refactoring.Title} ({refactoring.Id})"));

                    yield return(BulletItem(Bold("Syntax"), ": ", string.Join(", ", refactoring.Syntaxes.Select(f => f.Name))));

                    if (!string.IsNullOrEmpty(refactoring.Span))
                    {
                        yield return(BulletItem(Bold("Span"), ": ", refactoring.Span));
                    }

                    foreach (object item in GetRefactoringSamples(refactoring))
                    {
                        yield return(item);
                    }
                }
            }
        }
コード例 #2
0
        public static string CreateListOfAnalyzerOptions(RoslynatorMetadata metadata)
        {
            IEnumerable <string> options = metadata.GetAllAnalyzers()
                                           .SelectMany(f => f.Options)
                                           .Select(analyzerOption =>
            {
                string optionKey = analyzerOption.OptionKey;

                if (!optionKey.StartsWith("roslynator.", StringComparison.Ordinal))
                {
                    optionKey = $"roslynator.{analyzerOption.ParentId}.{optionKey}";
                }

                return(analyzerOption, value: optionKey + " = " + (analyzerOption.OptionValue ?? "true"));
            })
                                           .OrderBy(f => f.value)
                                           .Select(f => $"# {f.analyzerOption.Title}{NewLine}{f.value}");

            MDocument document = Document(
                Heading1("List of EditorConfig Options"),
                FencedCodeBlock(
                    string.Join(NewLine + NewLine, options),
                    "editorconfig"));

            document.AddFootnote();

            var format = new MarkdownFormat(tableOptions: MarkdownFormat.Default.TableOptions | TableOptions.FormatContent);

            return(document.ToString(format));
        }
コード例 #3
0
        public static string CreateAnalyzersByCategoryMarkdown(IEnumerable <AnalyzerDescriptor> analyzers, IComparer <string> comparer)
        {
            MDocument document = Document(
                Heading2("Roslynator Analyzers by Category"),
                Table(
                    TableRow("Category", "Title", "Id", TableColumn(HorizontalAlignment.Center, "Enabled by Default")),
                    GetRows()));

            document.AddFootnote();

            return(document.ToString());

            IEnumerable <MTableRow> GetRows()
            {
                foreach (IGrouping <string, AnalyzerDescriptor> grouping in analyzers
                         .GroupBy(f => MarkdownEscaper.Escape(f.Category))
                         .OrderBy(f => f.Key, comparer))
                {
                    foreach (AnalyzerDescriptor analyzer in grouping.OrderBy(f => f.Title, comparer))
                    {
                        yield return(TableRow(
                                         grouping.Key,
                                         Link(analyzer.Title.TrimEnd('.'), $"../../docs/analyzers/{analyzer.Id}.md"),
                                         analyzer.Id,
                                         CheckboxOrHyphen(analyzer.IsEnabledByDefault)));
                    }
                }
            }
        }
コード例 #4
0
        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)));
                }
            }
        }
コード例 #5
0
        public static void Main()
        {
            MDocument document = Document();

            Console.WriteLine(document.ToString());

            Console.ReadKey();
        }
コード例 #6
0
        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)));
        }
コード例 #7
0
        public static string CreateRefactoringsReadMe(IEnumerable <RefactoringDescriptor> refactorings, IComparer <string> comparer)
        {
            MDocument document = Document(
                Heading2("Roslynator Refactorings"),
                Table(
                    TableRow("Id", "Title", TableColumn(HorizontalAlignment.Center, "Enabled by Default")),
                    refactorings.OrderBy(f => f.Title, comparer).Select(f =>
            {
                return(TableRow(
                           f.Id,
                           Link(f.Title.TrimEnd('.'), $"../../docs/refactorings/{f.Id}.md"),
                           CheckboxOrHyphen(f.IsEnabledByDefault)));
            })));

            return(document.ToString());
        }
コード例 #8
0
        public static string CreateCompilerDiagnosticMarkdown(CompilerDiagnosticDescriptor diagnostic, IEnumerable <CodeFixDescriptor> codeFixes, IComparer <string> comparer)
        {
            MDocument document = Document(
                Heading1(diagnostic.Id),
                Table(
                    TableRow("Property", "Value"),
                    TableRow("Id", diagnostic.Id),
                    TableRow("Title", diagnostic.Title),
                    TableRow("Severity", diagnostic.Severity),
                    (!string.IsNullOrEmpty(diagnostic.HelpUrl)) ? TableRow("Official Documentation", Link("link", diagnostic.HelpUrl)) : null),
                Heading2("Code Fixes"),
                BulletList(codeFixes
                           .Where(f => f.FixableDiagnosticIds.Any(diagnosticId => diagnosticId == diagnostic.Id))
                           .Select(f => f.Title)
                           .OrderBy(f => f, comparer)));

            return(document.ToString(MarkdownFormat.Default.WithTableOptions(MarkdownFormat.Default.TableOptions | TableOptions.FormatContent)));
        }
コード例 #9
0
        public static string CreateRefactoringMarkdown(RefactoringDescriptor refactoring)
        {
            var format = new MarkdownFormat(tableOptions: MarkdownFormat.Default.TableOptions | TableOptions.FormatContent);

            MDocument document = Document(
                Heading2(refactoring.Title),
                Table(TableRow("Property", "Value"),
                      TableRow("Id", refactoring.Id),
                      TableRow("Title", refactoring.Title),
                      TableRow("Syntax", string.Join(", ", refactoring.Syntaxes.Select(f => f.Name))),
                      (!string.IsNullOrEmpty(refactoring.Span)) ? TableRow("Span", refactoring.Span) : null,
                      TableRow("Enabled by Default", CheckboxOrHyphen(refactoring.IsEnabledByDefault))),
                Heading3("Usage"),
                GetRefactoringSamples(refactoring),
                Link("full list of refactorings", "Refactorings.md"));

            return(document.ToString(format));
        }
コード例 #10
0
        public static string CreateAnalyzersReadMe(IEnumerable <AnalyzerDescriptor> analyzers, IComparer <string> comparer)
        {
            MDocument document = Document(
                Heading2("Roslynator Analyzers"),
                Link("Search Analyzers", "http://pihrt.net/Roslynator/Analyzers"),
                Table(
                    TableRow("Id", "Title", "Category", TableColumn(HorizontalAlignment.Center, "Enabled by Default")),
                    analyzers.OrderBy(f => f.Id, comparer).Select(f =>
            {
                return(TableRow(
                           f.Id,
                           Link(f.Title.TrimEnd('.'), $"../../docs/analyzers/{f.Id}.md"),
                           f.Category,
                           CheckboxOrHyphen(f.IsEnabledByDefault)));
            })));

            return(document.ToString());
        }
コード例 #11
0
        public static string CreateAnalyzerMarkdown(AnalyzerDescriptor analyzer)
        {
            var format = new MarkdownFormat(tableOptions: MarkdownFormat.Default.TableOptions | TableOptions.FormatContent);

            MDocument document = Document(
                Heading1($"{((analyzer.IsObsolete) ? "[deprecated] " : "")}{analyzer.Id}: {analyzer.Title.TrimEnd('.')}"),
                Table(
                    TableRow("Property", "Value"),
                    TableRow("Id", analyzer.Id),
                    TableRow("Category", analyzer.Category),
                    TableRow("Default Severity", analyzer.DefaultSeverity),
                    TableRow("Enabled by Default", CheckboxOrHyphen(analyzer.IsEnabledByDefault)),
                    TableRow("Supports Fade-Out", CheckboxOrHyphen(analyzer.SupportsFadeOut)),
                    TableRow("Supports Fade-Out Analyzer", CheckboxOrHyphen(analyzer.SupportsFadeOutAnalyzer))),
                (!string.IsNullOrEmpty(analyzer.Summary)) ? Raw(analyzer.Summary) : null,
                Samples(),
                GetLinks(analyzer.Links),
                Heading2("How to Suppress"),
                Heading3("SuppressMessageAttribute"),
                FencedCodeBlock($"[assembly: SuppressMessage(\"{analyzer.Category}\", \"{analyzer.Id}:{analyzer.Title}\", Justification = \"<Pending>\")]", LanguageIdentifiers.CSharp),
                Heading3("#pragma"),
                FencedCodeBlock($"#pragma warning disable {analyzer.Id} // {analyzer.Title}\r\n#pragma warning restore {analyzer.Id} // {analyzer.Title}", LanguageIdentifiers.CSharp),
                Heading3("Ruleset"),
                BulletItem(Link("How to configure rule set", "../HowToConfigureAnalyzers.md")));

            document.AddFootnote();

            return(document.ToString(format));

            IEnumerable <MElement> Samples()
            {
                IReadOnlyList <SampleDescriptor> samples = analyzer.Samples;

                if (samples.Count > 0)
                {
                    yield return(Heading2((samples.Count == 1) ? "Example" : "Examples"));

                    foreach (MElement item in GetSamples(samples, Heading3("Code with Diagnostic"), Heading3("Code with Fix")))
                    {
                        yield return(item);
                    }
                }
            }
        }
コード例 #12
0
        public static string CreateCodeFixesReadMe(IEnumerable <CompilerDiagnosticDescriptor> diagnostics, IComparer <string> comparer)
        {
            MDocument document = Document(
                Heading2("Compiler Diagnostics Fixable with Roslynator"),
                Table(
                    TableRow("Id", "Title"),
                    GetRows()));

            return(document.ToString());

            IEnumerable <MTableRow> GetRows()
            {
                foreach (CompilerDiagnosticDescriptor diagnostic in diagnostics
                         .OrderBy(f => f.Id, comparer))
                {
                    yield return(TableRow(
                                     Link(diagnostic.Id, $"../../docs/cs/{diagnostic.Id}.md"),
                                     diagnostic.Title));
                }
            }
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: pwyszynski/Snippetica
        private static void Main(string[] args)
        {
            _shortcuts = Pihrtsoft.Records.Document.ReadRecords(@"..\..\Data\Shortcuts.xml")
                         .Where(f => !f.HasTag(KnownTags.Disabled))
                         .Select(Mapper.MapShortcutInfo)
                         .ToArray();

            SnippetDirectory[] directories = LoadDirectories(@"..\..\Data\Directories.xml");

            ShortcutInfo.SerializeToXml(Path.Combine(VisualStudioExtensionProjectPath, "Shortcuts.xml"), _shortcuts);

            LoadLanguages();

            SaveChangedSnippets(directories);

            var visualStudio = new VisualStudioEnvironment();

            (List <SnippetGeneratorResult> visualStudioResults, List <Snippet> visualStudioSnippets) = GenerateSnippets(
                visualStudio,
                directories,
                VisualStudioExtensionProjectPath);

            var visualStudioCode = new VisualStudioCodeEnvironment();

            (List <SnippetGeneratorResult> visualStudioCodeResults, List <Snippet> visualStudioCodeSnippets) = GenerateSnippets(
                visualStudioCode,
                directories,
                VisualStudioCodeExtensionProjectPath);

            CheckDuplicateShortcuts(visualStudioSnippets, visualStudio);
            CheckDuplicateShortcuts(visualStudioCodeSnippets, visualStudioCode);

            IEnumerable <Language> languages = visualStudioResults
                                               .Concat(visualStudioCodeResults)
                                               .Select(f => f.Language)
                                               .Distinct();

            var document = new MDocument(
                Heading1(ProductName),
                BulletList(
                    CodeGenerationUtility.GetProjectSubtitle(languages),
                    BulletItem(Link("Release Notes", $"{MasterGitHubUrl}/{ChangeLogFileName}"), ".")));

#if !DEBUG
            MarkdownGenerator.GenerateProjectReadme(visualStudioResults, document, visualStudio.CreateProjectReadmeSettings(), addFootnote: false);

            MarkdownGenerator.GenerateProjectReadme(visualStudioCodeResults, document, visualStudioCode.CreateProjectReadmeSettings());

            IOUtility.WriteAllText(Path.Combine(SolutionDirectoryPath, ReadMeFileName), document.ToString(MarkdownFormat.Default.WithTableOptions(TableOptions.FormatHeader)), IOUtility.UTF8NoBom);
#endif

            Console.WriteLine("*** END ***");
            Console.ReadKey();
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: atifaziz/Orang
        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();
            }
        }
コード例 #15
0
        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();
            }
        }