private static string GenerateDirectoryReadme(SnippetDirectory snippetDirectory, CharacterSequence[] characterSequences, GeneralSettings settings) { using (var sw = new StringWriter()) { string directoryName = snippetDirectory.DirectoryName; sw.WriteLine($"## {directoryName}"); sw.WriteLine(); characterSequences = characterSequences? .Where(f => f.Languages.Select(language => settings.DirectoryNamePrefix + language.ToString()) .Contains(snippetDirectory.DirectoryName)).ToArray(); if (characterSequences?.Length > 0) { sw.WriteLine("### Quick Reference"); sw.WriteLine(); string filePath = $@"..\..\..\..\..\text\{directoryName}.md"; if (File.Exists(filePath)) { sw.WriteLine(File.ReadAllText(filePath, Encoding.UTF8)); sw.WriteLine(); } using (CharacterSequenceTableWriter tableWriter = CharacterSequenceTableWriter.Create()) { tableWriter.WriteTable(characterSequences); sw.Write(tableWriter.ToString()); } sw.WriteLine(); } if (!snippetDirectory.HasTag(KnownTags.Dev)) { sw.WriteLine($"* [full list of snippets](http://pihrt.net/Snippetica/Snippets?Language={snippetDirectory.Language})"); sw.WriteLine(); } sw.WriteLine("### List of Selected Snippets"); sw.WriteLine(); using (SnippetTableWriter tableWriter = SnippetTableWriter.CreateTitleWithLinkThenShortcut(snippetDirectory.Path)) { IEnumerable <Snippet> snippets = snippetDirectory .EnumerateSnippets() .Where(f => !f.HasTag(KnownTags.ExcludeFromReadme)); tableWriter.WriteTable(snippets); sw.Write(tableWriter.ToString()); } return(sw.ToString()); } }
public static void WriteDirectoryMarkdownFiles(SnippetDirectory snippetDirectory, string directoryPath, CharacterSequence[] characterSequences) { WriteDirectoryMarkdownFiles(snippetDirectory.EnumerateSnippets().ToArray(), directoryPath, characterSequences); }