Example #1
0
    public static Task VerifySnippets(
        this VerifyBase verifyBase,
        string markdownContent,
        List <Snippet> availableSnippets,
        List <string> snippetSourceFiles,
        IReadOnlyList <Include>?includes = null)
    {
        if (includes == null)
        {
            includes = Array.Empty <Include>();
        }

        var markdownProcessor = new MarkdownProcessor(
            snippets: availableSnippets.ToDictionary(),
            appendSnippetGroup: SimpleSnippetMarkdownHandling.AppendGroup,
            snippetSourceFiles: snippetSourceFiles,
            tocLevel: 2,
            writeHeader: true,
            includes: includes,
            rootDirectory: "c:/root");
        var stringBuilder = new StringBuilder();

        using var reader = new StringReader(markdownContent);
        using var writer = new StringWriter(stringBuilder);
        var processResult = markdownProcessor.Apply(reader, writer, "sourceFile");
        var output        = new
        {
            processResult.MissingSnippets,
            processResult.UsedSnippets,
            content = stringBuilder.ToString()
        };

        return(verifyBase.Verify(output));
    }
Example #2
0
    void Basic()
    {
        #region markdownProcessing

        // setup version convention and extract snippets from files
        var snippetExtractor = new DirectorySnippetExtractor(
            directoryFilter: x => true,
            fileFilter: s => s.EndsWith(".vm") || s.EndsWith(".cs"));
        var snippets = snippetExtractor.ReadSnippets(@"C:\path");

        // Merge with some markdown text
        var markdownProcessor = new MarkdownProcessor(snippets, SimpleSnippetMarkdownHandling.AppendGroup);

        using (var reader = File.OpenText(@"C:\path\inputMarkdownFile.md"))
            using (var writer = File.CreateText(@"C:\path\outputMarkdownFile.md"))
            {
                var result = markdownProcessor.Apply(reader, writer);

                // snippets that the markdown file expected but did not exist in the input snippets
                var missingSnippets = result.MissingSnippets;

                // snippets that the markdown file used
                var usedSnippets = result.UsedSnippets;
            }

        #endregion
    }
Example #3
0
    static void ProcessFile(string sourceFile, MarkdownProcessor markdownProcessor, string pagesDir)
    {
        var target = Path.Combine(pagesDir, Path.GetFileName(sourceFile));

        using (var reader = File.OpenText(sourceFile))
            using (var writer = File.CreateText(target))
            {
                var processResult = markdownProcessor.Apply(reader, writer);
                var missing       = processResult.MissingSnippets;
                if (missing.Any())
                {
                    throw new MissingSnippetsException(missing);
                }
            }
    }
Example #4
0
    public static void Verify(string markdownContent, List <Snippet> availableSnippets)
    {
        var markdownProcessor = new MarkdownProcessor(
            snippets: availableSnippets,
            appendSnippetGroup: SimpleSnippetMarkdownHandling.AppendGroup);
        var stringBuilder = new StringBuilder();

        using (var reader = new StringReader(markdownContent))
            using (var writer = new StringWriter(stringBuilder))
            {
                var processResult = markdownProcessor.Apply(reader, writer);
                var output        = new
                {
                    processResult.MissingSnippets,
                    processResult.UsedSnippets,
                    content = stringBuilder.ToString()
                };
                ObjectApprover.VerifyWithJson(output, s => s.Replace("\\r\\n", "\r\n"));
            }
    }
Example #5
0
    void Basic()
    {
        #region markdownProcessingSimple

        var directory = @"C:\path";

        // extract snippets from files
        var snippetExtractor = new DirectorySnippetExtractor();
        var snippets         = snippetExtractor.ReadSnippets(directory);

        // extract includes from files
        var includeFinder = new IncludeFinder();
        var includes      = includeFinder.ReadIncludes(directory);

        // Merge with some markdown text
        var markdownProcessor = new MarkdownProcessor(
            convention: DocumentConvention.SourceTransform,
            snippets: snippets.Lookup,
            includes: includes,
            appendSnippets: SimpleSnippetMarkdownHandling.Append,
            snippetSourceFiles: new List <string>(),
            tocLevel: 2,
            writeHeader: true,
            rootDirectory: directory,
            validateContent: true);

        var path = @"C:\path\inputMarkdownFile.md";
        using var reader = File.OpenText(path);
        using var writer = File.CreateText(@"C:\path\outputMarkdownFile.md");
        var result = markdownProcessor.Apply(reader, writer, path);
        // snippets that the markdown file expected but did not exist in the input snippets
        var missingSnippets = result.MissingSnippets;

        // snippets that the markdown file used
        var usedSnippets = result.UsedSnippets;

        #endregion
    }