Skip to content

Commit cce960b

Browse files
committed
reuse FileSnippetExtractor.GetLanguageFromPath
1 parent 72506b0 commit cce960b

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

src/MarkdownSnippets/Processing/MarkdownProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ Snippet FileToSnippet(string key, string file, string? path)
409409
endLine: lineCount,
410410
value: text,
411411
key: key,
412-
language: Path.GetExtension(file)[1..],
412+
language: FileSnippetExtractor.GetLanguageFromPath(file),
413413
path: path,
414414
expressiveCode: null);
415415
}

src/MarkdownSnippets/Reading/FileFinder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,12 @@ void ProcessMarkdown(string file)
109109

110110
static bool ShouldInclude(string file)
111111
{
112-
var extension = Path.GetExtension(file);
112+
var extension = FileSnippetExtractor.GetLanguageFromPath(file);
113113
if (extension == string.Empty)
114114
{
115115
return false;
116116
}
117117

118-
extension = extension[1..];
119118
return !SnippetFileExclusions.IsBinary(extension);
120119
}
121120
}

src/MarkdownSnippets/Reading/FileSnippetExtractor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static void AppendFileAsSnippet(ICollection<Snippet> snippets, string fil
8383
/// <param name="newLine">The string to use as a line separator in snippets.</param>
8484
public static IEnumerable<Snippet> Read(IEnumerable<string> paths, int maxWidth = int.MaxValue, string newLine = "\n") =>
8585
paths
86-
.Where(_ => SnippetFileExclusions.CanContainCommentsExtension(Path.GetExtension(_)[1..]))
86+
.Where(_ => SnippetFileExclusions.CanContainCommentsExtension(GetLanguageFromPath(_)))
8787
.SelectMany(path => Read(path, maxWidth, newLine));
8888

8989
/// <summary>
@@ -119,7 +119,7 @@ public static IEnumerable<Snippet> Read(TextReader textReader, string path, int
119119
return GetSnippets(textReader, path, maxWidth, newLine);
120120
}
121121

122-
static string GetLanguageFromPath(string path)
122+
public static string GetLanguageFromPath(string path)
123123
{
124124
var extension = Path.GetExtension(path);
125125
// ReSharper disable once ConstantConditionalAccessQualifier

0 commit comments

Comments
 (0)