Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Elastic.Markdown/IO/MarkdownFileFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ private DocumentationFile CreateMarkDownFile(IFileInfo file, BuildContext contex
if (context.Configuration.IsExcluded(relativePath))
return new ExcludedFile(file, sourceDirectory, context.Git.RepositoryName);

if (relativePath.Contains("_snippets"))
if (relativePath.Contains($"{Path.DirectorySeparatorChar}_snippets{Path.DirectorySeparatorChar}")
|| relativePath.StartsWith($"_snippets{Path.DirectorySeparatorChar}"))
return new SnippetFile(file, sourceDirectory, context.Git.RepositoryName);

// we ignore files in folders that start with an underscore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void ExtractInclusionPath(ParserContext context)

var file = Build.ReadFileSystem.FileInfo.New(IncludePath);

if (file.Directory != null && file.Directory.FullName.IndexOf("_snippets", StringComparison.Ordinal) < 0)
if (file.Directory != null && !file.Directory.FullName.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Contains("_snippets"))
{
this.EmitError($"{{include}} only supports including snippets from `_snippet` folders. `{IncludePath}` is not a snippet");
Found = false;
Expand Down
2 changes: 1 addition & 1 deletion tests/Elastic.Markdown.Tests/MockFileSystemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void GenerateDocSetYaml(
.EnumerateFiles(root.FullName, "*.md", SearchOption.AllDirectories);
foreach (var markdownFile in markdownFiles)
{
if (markdownFile.Contains("_snippet"))
if (markdownFile.Contains($"{Path.DirectorySeparatorChar}_snippets{Path.DirectorySeparatorChar}"))
continue;
var relative = fileSystem.Path.GetRelativePath(root.FullName, markdownFile);
yaml.WriteLine($" - file: {relative}");
Expand Down
29 changes: 29 additions & 0 deletions tests/Elastic.Markdown.Tests/OutputDirectoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,35 @@ public async Task CreatesDefaultOutputDirectory()
fileSystem.Directory.Exists(".artifacts").Should().BeTrue();
}

[Fact]
public void FilesWithSnippetsInNameNotTreatedAsSnippets()
{
var logger = new TestLoggerFactory(output);
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ "docs/docset.yml",
//language=yaml
new MockFileData("""
project: test
toc:
- file: index.md
- file: top_snippets.md
""") },
{ "docs/index.md", new MockFileData("# Test") },
{ "docs/top_snippets.md", new MockFileData("# Top Snippets") }
}, new MockFileSystemOptions
{
CurrentDirectory = Paths.WorkingDirectoryRoot.FullName
});
var collector = new TestDiagnosticsCollector(output);
var configurationContext = TestHelpers.CreateConfigurationContext(fileSystem);
var context = new BuildContext(collector, fileSystem, configurationContext);
var linkResolver = new TestCrossLinkResolver();
var set = new DocumentationSet(context, logger, linkResolver);

set.MarkdownFiles.Should().Contain(f => f.RelativePath.EndsWith("top_snippets.md"));
}

[Theory]
[MemberData(nameof(ValidFileNames))]
public void OutputFileValidationValidNames(string fileName)
Expand Down
Loading