Add CMake syntax highlighting and format detection

This commit is contained in:
ema
2025-07-09 04:16:19 +08:00
parent 631fd91219
commit 67dc0ce10d
6 changed files with 243 additions and 12 deletions

View File

@@ -20,11 +20,11 @@ using System.IO;
namespace QuickLook.Plugin.TextViewer.Detectors;
public sealed class CMakeListsDetector : IFormatDetector
public sealed class CMakeListsDetector : IConfusedFormatDetector
{
public string Name => "CMakeLists";
public string Name => "CMake";
public string Extension => ".txt";
public string Extension => ".cmake";
public bool Detect(string path, string text)
{

View File

@@ -24,7 +24,7 @@ public sealed class DockerfileDetector : IFormatDetector
{
public string Name => "Dockerfile";
public string Extension => ".df";
public string Extension => null;
public bool Detect(string path, string text)
{

View File

@@ -28,18 +28,26 @@ public class FormatDetector
new XMLDetector(),
new JSONDetector(),
new MakefileDetector(),
new CMakeListsDetector(),
//new HostsDetector(),
//new CMakeListsDetector(),
//new DockerfileDetector(),
];
public static IFormatDetector Detect(string path, string text)
public static IConfusedFormatDetector ResolveConfusedFormat(string path, string text)
{
_ = path;
if (string.IsNullOrWhiteSpace(text)) return null;
return Instance.TextDetectors.Where(detector => detector.Detect(path, text))
return Instance.TextDetectors
.Where(detector => detector is IConfusedFormatDetector && detector.Detect(path, text))
.FirstOrDefault() as IConfusedFormatDetector;
}
public static IFormatDetector Detect(string path, string text)
{
if (string.IsNullOrWhiteSpace(text)) return null;
return Instance.TextDetectors
.Where(detector => detector is not IConfusedFormatDetector && detector.Detect(path, text))
.FirstOrDefault();
}
}
@@ -52,3 +60,5 @@ public interface IFormatDetector
public bool Detect(string path, string text);
}
public interface IConfusedFormatDetector : IFormatDetector;

View File

@@ -24,7 +24,7 @@ public sealed class HostsDetector : IFormatDetector
{
public string Name => "Hosts";
public string Extension => ".hosts";
public string Extension => null;
public bool Detect(string path, string text)
{