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

@@ -46,16 +46,29 @@ public class HighlightingThemeManager
{
if (Light is null || Dark is null) return HighlightingTheme.Default;
var useFormatDetector = SettingHelper.Get("UseFormatDetector", true, "QuickLook.Plugin.TextViewer");
var highlightingTheme = GetDefinitionByExtension(nameof(Dark), extension);
if (useFormatDetector && FormatDetector.ResolveConfusedFormat(path, text) is IConfusedFormatDetector confusedFormatDetector)
{
if (!string.IsNullOrEmpty(confusedFormatDetector.Extension))
{
highlightingTheme = GetDefinitionByExtension(nameof(Dark), confusedFormatDetector.Extension)
?? GetDefinitionByExtension(nameof(Light), confusedFormatDetector.Extension);
}
else
{
highlightingTheme = GetDefinition(nameof(Dark), confusedFormatDetector.Name)
?? GetDefinition(nameof(Light), confusedFormatDetector.Name);
}
}
if (highlightingTheme == null)
{
highlightingTheme = GetDefinitionByExtension(nameof(Light), extension);
if (highlightingTheme == null)
{
var useFormatDetector = SettingHelper.Get("UseFormatDetector", true, "QuickLook.Plugin.TextViewer");
if (useFormatDetector && FormatDetector.Detect(path, text)?.Extension is string detectExtension)
{
highlightingTheme = GetDefinitionByExtension(nameof(Dark), detectExtension)
@@ -85,6 +98,24 @@ public class HighlightingThemeManager
return highlightingTheme;
}
private static HighlightingTheme GetDefinition(string theme, string extension)
{
var highlightingManager = theme == nameof(Dark) ? Dark : Light;
var def = highlightingManager.GetDefinition(extension);
if (def != null)
{
return new HighlightingTheme()
{
Theme = theme,
HighlightingManager = highlightingManager,
SyntaxHighlighting = def,
Extension = extension,
};
}
return null;
}
private static HighlightingTheme GetDefinitionByExtension(string theme, string extension)
{
var highlightingManager = theme == nameof(Dark) ? Dark : Light;