Skip to content

Commit

Permalink
make includes and snippets case sensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Mar 5, 2024
1 parent 95fb824 commit 5e63f4f
Show file tree
Hide file tree
Showing 29 changed files with 69 additions and 75 deletions.
4 changes: 2 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ https://nuget.org/packages/MarkdownSnippets/ [![NuGet Status](https://img.shield
## Reading snippets from files

<!-- snippet: ReadingFilesSimple -->
<a id='snippet-readingfilessimple'></a>
<a id='snippet-ReadingFilesSimple'></a>
```cs
var files = Directory.EnumerateFiles(@"C:\path", "*.cs", SearchOption.AllDirectories);

var snippets = FileSnippetExtractor.Read(files);
```
<sup><a href='/src/Tests/Snippets/Usage.cs#L8-L14' title='Snippet source file'>snippet source</a> | <a href='#snippet-readingfilessimple' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/Snippets/Usage.cs#L8-L14' title='Snippet source file'>snippet source</a> | <a href='#snippet-ReadingFilesSimple' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
8 changes: 4 additions & 4 deletions docs/exclusion.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ When scanning for snippets the following are ignored:
* All binary files as defined by https://github.com/sindresorhus/binary-extensions/:

<!-- snippet: BinaryFileExtensions -->
<a id='snippet-binaryfileextensions'></a>
<a id='snippet-BinaryFileExtensions'></a>
```cs
"user",
// extra binary
Expand Down Expand Up @@ -318,17 +318,17 @@ When scanning for snippets the following are ignored:
"zip",
"zipx"
```
<sup><a href='/src/MarkdownSnippets/Reading/Exclusions/SnippetFileExclusions.cs#L29-L298' title='Snippet source file'>snippet source</a> | <a href='#snippet-binaryfileextensions' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/MarkdownSnippets/Reading/Exclusions/SnippetFileExclusions.cs#L29-L298' title='Snippet source file'>snippet source</a> | <a href='#snippet-BinaryFileExtensions' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

* Files that cannot contain comments:

<!-- snippet: NoAcceptCommentsExtensions -->
<a id='snippet-noacceptcommentsextensions'></a>
<a id='snippet-NoAcceptCommentsExtensions'></a>
```cs
"csv",
"json",
"geojson"
```
<sup><a href='/src/MarkdownSnippets/Reading/Exclusions/SnippetFileExclusions.cs#L20-L24' title='Snippet source file'>snippet source</a> | <a href='#snippet-noacceptcommentsextensions' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/MarkdownSnippets/Reading/Exclusions/SnippetFileExclusions.cs#L20-L24' title='Snippet source file'>snippet source</a> | <a href='#snippet-NoAcceptCommentsExtensions' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
4 changes: 2 additions & 2 deletions docs/max-width.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The Max Width setting is used to control the maximum characters per line of a sn
### Code Api

<!-- snippet: DirectoryMarkdownProcessorRunMaxWidth -->
<a id='snippet-directorymarkdownprocessorrunmaxwidth'></a>
<a id='snippet-DirectoryMarkdownProcessorRunMaxWidth'></a>
```cs
var processor = new DirectoryMarkdownProcessor(
"targetDirectory",
Expand All @@ -42,7 +42,7 @@ var processor = new DirectoryMarkdownProcessor(
snippetDirectoryIncludes: _ => true);
processor.Run();
```
<sup><a href='/src/Tests/Snippets/Usage.cs#L33-L43' title='Snippet source file'>snippet source</a> | <a href='#snippet-directorymarkdownprocessorrunmaxwidth' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/Snippets/Usage.cs#L33-L43' title='Snippet source file'>snippet source</a> | <a href='#snippet-DirectoryMarkdownProcessorRunMaxWidth' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ mdsnippets --omit-snippet-links true
#### How links are constructed

<!-- snippet: BuildLink -->
<a id='snippet-buildlink'></a>
<a id='snippet-BuildLink'></a>
```cs
if (linkFormat == LinkFormat.GitHub)
{
Expand All @@ -325,7 +325,7 @@ if (linkFormat == LinkFormat.GitLab)
return;
}
```
<sup><a href='/src/MarkdownSnippets/Processing/SnippetMarkdownHandling.cs#L96-L120' title='Snippet source file'>snippet source</a> | <a href='#snippet-buildlink' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/MarkdownSnippets/Processing/SnippetMarkdownHandling.cs#L96-L120' title='Snippet source file'>snippet source</a> | <a href='#snippet-BuildLink' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
2 changes: 1 addition & 1 deletion src/MarkdownSnippets/Processing/IncludeProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static string GetIncludeKey(string substring)

void Inner(List<Line> lines, Line line, List<Include> used, int index, List<MissingInclude> missing, string includeKey, string? relativePath)
{
var include = includes.SingleOrDefault(_ => string.Equals(_.Key, includeKey, StringComparison.OrdinalIgnoreCase));
var include = includes.SingleOrDefault(_ => _.Key == includeKey);
if (include != null)
{
AddInclude(lines, line, used, index, include, true);
Expand Down
2 changes: 0 additions & 2 deletions src/MarkdownSnippets/Reading/StartEndTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ internal static bool IsStartRegion(
return false;
}

key = key.ToLowerInvariant();
return true;
}

Expand Down Expand Up @@ -130,7 +129,6 @@ Key cannot contain whitespace or start/end with symbols.
""");
}

key = key.ToLowerInvariant();
return true;
}

Expand Down
7 changes: 3 additions & 4 deletions src/MarkdownSnippets/SnippetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ static class SnippetExtensions
{
public static Dictionary<string, IReadOnlyList<Snippet>> ToDictionary(this IEnumerable<Snippet> value) =>
value
.GroupBy(_ => _.Key.ToLowerInvariant(), StringComparer.OrdinalIgnoreCase)
.GroupBy(_ => _.Key)
.ToDictionary(
keySelector: _ => _.Key.ToLowerInvariant(),
elementSelector: _ => _.OrderBy(ScrubPath).ToReadonlyList(),
comparer: StringComparer.OrdinalIgnoreCase);
keySelector: _ => _.Key,
elementSelector: _ => _.OrderBy(ScrubPath).ToReadonlyList());

static string? ScrubPath(Snippet snippet) =>
snippet.Path?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ before

theValue1<!-- singleLineInclude: theKey. path: {CurrentDirectory}thePath -->

theValue1<!-- singleLineInclude: theKey. path: {CurrentDirectory}thePath -->

theValue1<!-- singleLineInclude: theKey. path: {CurrentDirectory}thePath -->
theValue2<!-- singleLineInclude: TheKey. path: {CurrentDirectory}thePath -->

after
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
UsedSnippets: [
{
Key: thekey,
Key: theKey,
Language: cs,
Value: Snippet,
Error: ,
FileLocation: thePath(1-2),
IsInError: false
},
{
Key: TheKey,
Language: cs,
Value: Snippet,
Error: ,
Expand All @@ -24,11 +32,5 @@ Snippet
```
<!-- endSnippet -->

<!-- snippet: thekey -->
```cs
Snippet
```
<!-- endSnippet -->

after
}
17 changes: 7 additions & 10 deletions src/Tests/MarkdownProcessor/MarkdownProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public Task WithSingleInclude()
Include.Build("theKey", lines, Path.GetFullPath("thePath"))
});
}

[Fact]
public Task WithMixedCaseInclude()
{
Expand All @@ -133,23 +134,18 @@ public Task WithMixedCaseInclude()

include: theKey

include: thekey

include: TheKey

after

""";
var lines = new List<string>
{
"theValue1"
};
return SnippetVerifier.Verify(
DocumentConvention.SourceTransform,
content,
includes: new[]
{
Include.Build("theKey", lines, Path.GetFullPath("thePath"))
Include.Build("theKey", ["theValue1"], Path.GetFullPath("thePath")),
Include.Build("TheKey", ["theValue2"], Path.GetFullPath("thePath")),
});
}

Expand Down Expand Up @@ -182,16 +178,17 @@ public Task WithMixedCaseSnippet()

snippet: TheKey

snippet: thekey

after

""";

return SnippetVerifier.Verify(
DocumentConvention.SourceTransform,
content,
snippets: [SnippetBuild("cs", "thekey")]);
snippets: [
SnippetBuild("cs", "theKey"),
SnippetBuild("cs", "TheKey"),
]);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Usage
IsInError: false
},
{
Key: readingfilessimple,
Key: ReadingFilesSimple,
Language: cs,
Value:
var files = Directory.EnumerateFiles(@"C:/path", "*.cs", SearchOption.AllDirectories);
Expand All @@ -58,7 +58,7 @@ var snippets = FileSnippetExtractor.Read(files);,
IsInError: false
},
{
Key: directorymarkdownprocessorrun,
Key: DirectoryMarkdownProcessorRun,
Language: cs,
Value:
var processor = new DirectoryMarkdownProcessor(
Expand All @@ -72,7 +72,7 @@ processor.Run();,
IsInError: false
},
{
Key: directorymarkdownprocessorrunmaxwidth,
Key: DirectoryMarkdownProcessorRunMaxWidth,
Language: cs,
Value:
var processor = new DirectoryMarkdownProcessor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
Key: codekey,
Key: CodeKey,
Language: cs,
Value: The Code,
Error: ,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
Key: codekey,
Key: CodeKey,
Language: cs,
Value: <configSections/>,
Error: ,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
Key: codekey,
Key: CodeKey,
Language: cs,
Value:
BeforeWhiteSpace
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
Key: codekey,
Key: CodeKey,
Language: cs,
Value: <configSections/>,
Error: ,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
Key: codekey,
Key: CodeKey,
Language: cs,
Value: the code,
Error: ,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
Key: codekey,
Key: CodeKey,
Language: cs,
Value: the code,
Error: ,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
Key: codekey,
Key: CodeKey,
Language: cs,
Value:
A
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
Key: keychild,
Key: KeyChild,
Language: cs,
Value:
b
Expand All @@ -10,7 +10,7 @@ c,
IsInError: false
},
{
Key: keyparent,
Key: KeyParent,
Error: Snippet was not closed,
FileLocation: path.cs(3-3),
IsInError: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
Key: keychild,
Key: KeyChild,
Language: cs,
Value: b,
Error: ,
FileLocation: path.cs(3-5),
IsInError: false
},
{
Key: keyparent,
Key: KeyParent,
Language: cs,
Value:
a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
Key: keychild,
Key: KeyChild,
Language: cs,
Value: b,
Error: ,
FileLocation: path.cs(3-5),
IsInError: false
},
{
Key: keyparent,
Key: KeyParent,
Language: cs,
Value:
a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
Key: keychild,
Key: KeyChild,
Language: cs,
Value: b,
Error: ,
FileLocation: path.cs(4-6),
IsInError: false
},
{
Key: keyparent,
Key: KeyParent,
Language: cs,
Value:
a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
Key: keychild,
Key: KeyChild,
Language: cs,
Value: b,
Error: ,
FileLocation: path.cs(3-5),
IsInError: false
},
{
Key: keyparent,
Key: KeyParent,
Language: cs,
Value:
a
Expand Down
Loading

0 comments on commit 5e63f4f

Please sign in to comment.