Skip to content

Commit

Permalink
fix bug with nested md source dir (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Jan 10, 2023
1 parent 90d88cc commit b14d153
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591</NoWarn>
<Version>24.5.0</Version>
<Version>24.5.1</Version>
<LangVersion>11</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>Markdown, Snippets, mdsnippets, documentation, MarkdownSnippets</PackageTags>
Expand Down
2 changes: 2 additions & 0 deletions src/MarkdownSnippets/Processing/DirectoryMarkdownProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ void ProcessFile(string sourceFile, MarkdownProcessor markdownProcessor)

void WriteLines(string target, List<Line> lines)
{
var directoryName = Path.GetDirectoryName(target)!;
Directory.CreateDirectory(directoryName);
using var writer = File.CreateText(target);
writer.NewLine = newLine;
foreach (var line in lines)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
snippet: snippet1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/mdsource/Nested/one.source.md
snippet: snippet1

/Nested/one.md
<!-- snippet: snippet1 -->
<a id='snippet-snippet1'></a>
```cs
the code from snippet1
```
<sup><a href='#snippet-snippet1' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

24 changes: 24 additions & 0 deletions src/Tests/DirectoryMarkdownProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,30 @@ public Task Convention()

return Verify(builder.ToString());
}
[Fact]
public Task ConventionWithNestedDir()
{
var root = Path.GetFullPath("DirectoryMarkdownProcessor/ConventionWithNestedDir");
var processor = new DirectoryMarkdownProcessor(
root,
writeHeader: false,
newLine: "\r",
directoryIncludes: _ => true,
markdownDirectoryIncludes: _ => true,
snippetDirectoryIncludes: _ => true);
processor.AddSnippets(SnippetBuild("snippet1"));
processor.Run();

var builder = new StringBuilder();
foreach (var file in Directory.EnumerateFiles(root, "*.*", SearchOption.AllDirectories).OrderBy(_ => _))
{
builder.AppendLineN(file.Replace(root, ""));
builder.AppendLineN(File.ReadAllText(file));
builder.AppendLineN();
}

return Verify(builder.ToString());
}

[Fact]
public void MustErrorByDefaultWhenIncludesAreMissing()
Expand Down

0 comments on commit b14d153

Please sign in to comment.