Skip to content

Commit

Permalink
Fix endSnippet block getting removed for missing snippet (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticmind committed Jun 1, 2021
1 parent 6bc078e commit 8770f70
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/MarkdownSnippets/Processing/MarkdownProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ void ProcessSnippetLine(Action<string> appendLine, List<MissingSnippet> missings

MissingSnippet missing = new(key, line.LineNumber, line.Path);
missings.Add(missing);
appendLine("```");
appendLine($"** Could not find snippet '{key}' **");
appendLine("```");
appendLine("<!-- endSnippet -->");
}

bool TryGetSnippets(string key, string? relativePath, string? linePath, out IReadOnlyList<Snippet> snippetsForKey)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- snippet: missing.txt -->
<!-- endSnippet -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- snippet: missing.txt -->
```
** Could not find snippet 'missing.txt' **
```
<!-- endSnippet -->
19 changes: 19 additions & 0 deletions src/Tests/DirectoryMarkdownProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@ public Task InPlaceOverwriteUrlInclude()
return Verifier.Verify(File.ReadAllTextAsync(result));
}

[Fact]
public Task InPlaceOverwriteWithFileSnippetMissing()
{
var root = Path.GetFullPath("DirectoryMarkdownProcessor/InPlaceOverwriteWithFileSnippetMissing");
DirectoryMarkdownProcessor processor = new(
root,
convention: DocumentConvention.InPlaceOverwrite,
writeHeader: false,
directoryIncludes: _ => true,
markdownDirectoryIncludes: _ => true,
snippetDirectoryIncludes: _ => true,
treatMissingAsWarning: true);

processor.Run();

FileInfo fileInfo = new(Path.Combine(root, "file.md"));
return Verifier.VerifyFile(fileInfo);
}

[Fact]
public void ReadOnly()
{
Expand Down

0 comments on commit 8770f70

Please sign in to comment.