mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 17:59:17 +00:00
Add CMake syntax highlighting and format detection
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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;
|
||||
|
@@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user