public void ReadOnly() { var root = Path.GetFullPath("DirectoryMarkdownProcessor/Readonly"); try { var processor = new DirectoryMarkdownProcessor( root, writeHeader: false, readOnly: true); processor.AddSnippets( SnippetBuild("snippet1"), SnippetBuild("snippet2") ); processor.Run(); var fileInfo = new FileInfo(Path.Combine(root, "one.md")); Assert.True(fileInfo.IsReadOnly); } finally { foreach (var file in Directory.EnumerateFiles(root)) { FileEx.ClearReadOnly(file); } } }
public Task NonMd() { var root = Path.GetFullPath("DirectoryMarkdownProcessor/NonMd"); var processor = new DirectoryMarkdownProcessor( root, writeHeader: false, documentExtensions: new List <string> { "txt" }, newLine: "\n"); processor.AddSnippets( SnippetBuild("snippet1"), SnippetBuild("snippet2") ); processor.Run(); var builder = new StringBuilder(); foreach (var file in Directory.EnumerateFiles(root, "*.*", SearchOption.AllDirectories)) { builder.AppendLine(file.Replace(root, "")); builder.AppendLine(File.ReadAllText(file)); builder.AppendLine(); } return(Verifier.Verify(builder.ToString())); }
public Task ExplicitFileIncludeWithSnippetAtEnd() { var root = Path.GetFullPath("DirectoryMarkdownProcessor/ExplicitFileIncludeWithSnippetAtEnd"); var processor = new DirectoryMarkdownProcessor(root, writeHeader: false, newLine: "\r"); processor.AddSnippets(SnippetBuild("snippet1")); processor.Run(); var result = Path.Combine(root, "one.md"); return(Verifier.Verify(File.ReadAllTextAsync(result))); }
public Task InPlaceOverwriteExists() { var root = Path.GetFullPath("DirectoryMarkdownProcessor/InPlaceOverwriteExists"); var processor = new DirectoryMarkdownProcessor( root, writeHeader: false, convention: DocumentConvention.InPlaceOverwrite); processor.AddSnippets(SnippetBuild("snippet1", "thePath")); processor.Run(); var fileInfo = new FileInfo(Path.Combine(root, "file.md")); return(Verifier.VerifyFile(fileInfo)); }
static async Task Inner(string targetDirectory, ConfigInput configInput) { var(fileConfig, configFilePath) = ConfigReader.Read(targetDirectory); var configResult = ConfigDefaults.Convert(fileConfig, configInput); var message = LogBuilder.BuildConfigLogMessage(targetDirectory, configResult, configFilePath); Console.WriteLine(message); var processor = new DirectoryMarkdownProcessor( targetDirectory, log: Console.WriteLine, directoryFilter: ExcludeToFilterBuilder.ExcludesToFilter(configResult.Exclude), readOnly: configResult.ReadOnly, writeHeader: configResult.WriteHeader, header: configResult.Header, urlPrefix: configResult.UrlPrefix, linkFormat: configResult.LinkFormat, convention: configResult.Convention, tocExcludes: configResult.TocExcludes, documentExtensions: configResult.DocumentExtensions, tocLevel: configResult.TocLevel, treatMissingAsWarning: configResult.TreatMissingAsWarning, maxWidth: configResult.MaxWidth, validateContent: configResult.ValidateContent, hashSnippetAnchors: configResult.HashSnippetAnchors); var snippets = new List <Snippet>(); await snippets.AppendUrlsAsSnippets(configResult.UrlsAsSnippets); processor.AddSnippets(snippets); try { processor.Run(); } catch (SnippetException exception) { Console.WriteLine($"Failed: {exception.Message}"); Environment.Exit(1); } }
public Task Convention() { var root = Path.GetFullPath("DirectoryMarkdownProcessor/Convention"); var processor = new DirectoryMarkdownProcessor(root, writeHeader: false); processor.AddSnippets( SnippetBuild("snippet1"), SnippetBuild("snippet2") ); processor.Run(); var builder = new StringBuilder(); foreach (var file in Directory.EnumerateFiles(root, "*.*", SearchOption.AllDirectories)) { builder.AppendLine(file.Replace(root, "")); builder.AppendLine(File.ReadAllText(file)); builder.AppendLine(); } return(Verify(builder.ToString())); }