Skip to content
Merged
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
4 changes: 2 additions & 2 deletions docs/exclusion.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ All binary files as defined by https://github.com/sindresorhus/binary-extensions
"zip",
"zipx"
```
<sup><a href='/src/MarkdownSnippets/Reading/Exclusions/SnippetFileExclusions.cs#L30-L299' 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#L47-L316' title='Snippet source file'>snippet source</a> | <a href='#snippet-BinaryFileExtensions' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -378,5 +378,5 @@ Files that cannot contain comments are excluded.
"geojson",
"sln"
```
<sup><a href='/src/MarkdownSnippets/Reading/Exclusions/SnippetFileExclusions.cs#L16-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#L14-L22' title='Snippet source file'>snippet source</a> | <a href='#snippet-NoAcceptCommentsExtensions' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
3 changes: 2 additions & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
<PackageVersion Include="Polyfill" Version="9.7.2" />
<PackageVersion Include="ProjectDefaults" Version="1.0.170" />
<PackageVersion Include="ProjectFiles" Version="0.4.0" />
<PackageVersion Include="System.Collections.Immutable" Version="10.0.2" />
<PackageVersion Include="System.Memory" Version="4.6.3" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="Verify.DiffPlex" Version="3.1.2" />
<PackageVersion Include="Verify.XunitV3" Version="31.9.4" />
<PackageVersion Include="xunit.v3" Version="3.2.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
</ItemGroup>
</Project>
</Project>
67 changes: 33 additions & 34 deletions src/MarkdownSnippets/ContentValidation.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
static class ContentValidation
{
static Dictionary<string, string> phrases = new()
{
{"a majority of ", "most"},
{"a number of", "some or many"},
{"at an early date", "soon"},
{"at the conclusion of", "after or following"},
{"at the present time", "now"},
{"at this point in time", "now"},
{"based on the fact that", "because or since"},
{"despite the fact that", "although"},
{"due to the fact that", "because"},
{"during the course of", "during"},
{"during the time that", "during or while"},
{"have the capability to", "can"},
{"in connection with", "about"},
{"in order to", "to"},
{"in regard to ", "regarding or about"},
{"in the event of", "if"},
{"in view of the fact that", "because"},
{"it is often the case that", "often"},
{"make reference to ", "refer to"},
{"of the opinion that", "think that "},
{"on a daily basis", "daily"},
{"on the grounds that", "because"},
{"prior to", "before"},
{"so as to", "to"},
{"subsequent to", "after"},
{"take into consideration", "consider"},
{"until such time as", "until"},
{"a lot", "many"},
{"sort of", "similar or approximately"},
{"kind of", "similar or approximately "}
};
static FrozenDictionary<string, string> phrases = FrozenDictionary.Create<string, string>([
new("a majority of ", "most"),
new("a number of", "some or many"),
new("at an early date", "soon"),
new("at the conclusion of", "after or following"),
new("at the present time", "now"),
new("at this point in time", "now"),
new("based on the fact that", "because or since"),
new("despite the fact that", "although"),
new("due to the fact that", "because"),
new("during the course of", "during"),
new("during the time that", "during or while"),
new("have the capability to", "can"),
new("in connection with", "about"),
new("in order to", "to"),
new("in regard to ", "regarding or about"),
new("in the event of", "if"),
new("in view of the fact that", "because"),
new("it is often the case that", "often"),
new("make reference to ", "refer to"),
new("of the opinion that", "think that "),
new("on a daily basis", "daily"),
new("on the grounds that", "because"),
new("prior to", "before"),
new("so as to", "to"),
new("subsequent to", "after"),
new("take into consideration", "consider"),
new("until such time as", "until"),
new("a lot", "many"),
new("sort of", "similar or approximately"),
new("kind of", "similar or approximately ")
]);

static List<string> invalidStrings;

Expand Down Expand Up @@ -135,4 +134,4 @@ static string Clean(string input)
span[index] = ' ';
});
}
}
}
2 changes: 1 addition & 1 deletion src/MarkdownSnippets/Downloader/FileNameFromUrl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
static class FileNameFromUrl
{
static HashSet<char> invalid = [..Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars())];
static FrozenSet<char> invalid = Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars()).ToFrozenSet();

public static string ConvertToFileName(string url)
{
Expand Down
3 changes: 2 additions & 1 deletion src/MarkdownSnippets/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
global using System.Diagnostics.CodeAnalysis;
global using System.Collections.Frozen;
global using System.Diagnostics.CodeAnalysis;
global using System.Net;
global using System.Net.Http;
global using System.Text.RegularExpressions;
Expand Down
3 changes: 2 additions & 1 deletion src/MarkdownSnippets/MarkdownSnippets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<PackageReference Include="Microsoft.Sbom.Targets" PrivateAssets="all" />
<PackageReference Include="ProjectDefaults" PrivateAssets="all" />
<PackageReference Include="Polyfill" PrivateAssets="all" />
<PackageReference Include="System.Collections.Immutable" Condition="'$(TargetFramework)' != 'net10.0'"/>
<PackageReference Include="System.Memory" Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard' OR '$(TargetFrameworkIdentifier)' == '.NETFramework' OR '$(TargetFrameworkIdentifier)' == '.NETCOREAPP'" />
<PackageReference Include="System.Net.Http" Condition="'$(TargetFramework)' == 'net48'" />
</ItemGroup>
</Project>
</Project>
66 changes: 56 additions & 10 deletions src/MarkdownSnippets/Reading/Exclusions/SnippetFileExclusions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
public static class SnippetFileExclusions
{
public static bool IsBinary(string extension) =>
BinaryFileExtensions.Contains(extension);
binaryFileExtensionsFrozen.Contains(extension);

public static bool CanContainCommentsExtension(string extension) =>
!NoAcceptCommentsExtensions.Contains(extension);
!noAcceptCommentsExtensionsFrozen.Contains(extension);

public static HashSet<string> NoAcceptCommentsExtensions { get; set; } =
new(StringComparer.OrdinalIgnoreCase)
{
static FrozenSet<string> noAcceptCommentsExtensionsFrozen = FrozenSet.Create(
StringComparer.OrdinalIgnoreCase,
source:
[
//files that dont accept comments hence cant contain snippets

#region NoAcceptCommentsExtensions
Expand All @@ -22,11 +23,34 @@ public static bool CanContainCommentsExtension(string extension) =>
"sln"

#endregion
};
]);

public static void AddNoAcceptCommentsExtensions(params string[] extensions)
{
var set = new HashSet<string>(noAcceptCommentsExtensionsFrozen, StringComparer.OrdinalIgnoreCase);
foreach (var extension in extensions)
{
set.Add(extension);
}

public static HashSet<string> BinaryFileExtensions { get; set; } =
new(StringComparer.OrdinalIgnoreCase)
noAcceptCommentsExtensionsFrozen = set.ToFrozenSet(StringComparer.OrdinalIgnoreCase);
}

public static void RemoveNoAcceptCommentsExtensions(params string[] extensions)
{
var set = new HashSet<string>(noAcceptCommentsExtensionsFrozen, StringComparer.OrdinalIgnoreCase);
foreach (var extension in extensions)
{
set.Remove(extension);
}

noAcceptCommentsExtensionsFrozen = set.ToFrozenSet(StringComparer.OrdinalIgnoreCase);
}

static FrozenSet<string> binaryFileExtensionsFrozen = FrozenSet.Create(
StringComparer.OrdinalIgnoreCase,
source:
[
#region BinaryFileExtensions

"user",
Expand Down Expand Up @@ -297,5 +321,27 @@ public static bool CanContainCommentsExtension(string extension) =>
"zipx"

#endregion
};
}
]);

public static void AddBinaryFileExtensions(params string[] extensions)
{
var set = new HashSet<string>(binaryFileExtensionsFrozen, StringComparer.OrdinalIgnoreCase);
foreach (var extension in extensions)
{
set.Add(extension);
}

binaryFileExtensionsFrozen = set.ToFrozenSet(StringComparer.OrdinalIgnoreCase);
}

public static void RemoveBinaryFileExtensions(params string[] extensions)
{
var set = new HashSet<string>(binaryFileExtensionsFrozen, StringComparer.OrdinalIgnoreCase);
foreach (var extension in extensions)
{
set.Remove(extension);
}

binaryFileExtensionsFrozen = set.ToFrozenSet(StringComparer.OrdinalIgnoreCase);
}
}
8 changes: 4 additions & 4 deletions src/MarkdownSnippets/Reading/FileSnippetExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static Task AppendUrlAsSnippet(this ICollection<Snippet> snippets, string
/// Each url will be accessible using the file name as a key. Any snippets within the files will be extracted and accessible as individual keyed snippets.
/// </summary>
public static Task AppendUrlsAsSnippets(this ICollection<Snippet> snippets, params string[] urls) =>
AppendUrlsAsSnippets(snippets, (IEnumerable<string>) urls);
snippets.AppendUrlsAsSnippets((IEnumerable<string>) urls);

/// <summary>
/// Each url will be accessible using the file name as a key. Any snippets within the files will be extracted and accessible as individual keyed snippets.
Expand All @@ -27,7 +27,7 @@ public static async Task AppendUrlsAsSnippets(this ICollection<Snippet> snippets
{
foreach (var url in urls)
{
await AppendUrlAsSnippet(snippets, url);
await snippets.AppendUrlAsSnippet(url);
}
}

Expand Down Expand Up @@ -63,7 +63,7 @@ public static void AppendFilesAsSnippets(this ICollection<Snippet> snippets, par
{
foreach (var filePath in filePaths)
{
AppendFileAsSnippet(snippets, filePath);
snippets.AppendFileAsSnippet(filePath);
}
}

Expand Down Expand Up @@ -211,4 +211,4 @@ static Snippet BuildSnippet(string path, LoopStack loopStack, string language, i
expressiveCode: loopState.ExpressiveCode
);
}
}
}