From 6deadf9d730b0d8d8aefa672a1f5d84ce12fc9a0 Mon Sep 17 00:00:00 2001 From: ema Date: Mon, 26 May 2025 05:42:27 +0800 Subject: [PATCH] Fix highlighting name --- .../QuickLook.Plugin.TextViewer/Plugin.cs | 34 ++++++- .../Syntax/Light/HLSL.xshd | 91 +++++++++++++++++++ .../Syntax/Light/JavaScript.xshd | 2 +- .../Light/zzz-After-JavaScript-HTML.xshd | 10 -- QuickLook/Helpers/Updater.cs | 2 +- 5 files changed, 126 insertions(+), 13 deletions(-) create mode 100644 QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Light/HLSL.xshd diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs index d04079b..6d0db09 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs @@ -181,7 +181,7 @@ public class Plugin : IViewer Debug.WriteLine(resourceName); var hlm = resourceName.Contains(".Syntax.Dark.") ? _hlmDark : _hlmLight; - var ext = Path.GetFileNameWithoutExtension(resourceName); + var ext = Path.GetFileNameWithoutExtension(resourceName.ToResourceDummyName()); using var reader = new XmlTextReader(s); var xshd = HighlightingLoader.LoadXshd(reader); var highlightingDefinition = HighlightingLoader.Load(xshd, hlm); @@ -216,3 +216,35 @@ public class Plugin : IViewer } } } + +file static class ResourceNameHelper +{ + /// + /// Converts a resource name (using '.' as separators) into a dummy file path + /// by replacing inner dots with backslashes, while preserving the file extension. + /// + /// Example: + /// Input: "Resources.Images.icon.png" + /// Output: "Resources\Images\icon.png" + /// + /// Input: "Assets.Sounds.music.background.mp3" + /// Output: "Assets\Sounds\music\background.mp3" + /// + /// The embedded resource name (excluding the default namespace). + /// A string representing the resource as a dummy file path. + public static string ToResourceDummyName(this string resourceName) + { + if (string.IsNullOrWhiteSpace(resourceName)) + return resourceName; + + int lastDotIndex = resourceName.LastIndexOf('.'); + if (lastDotIndex <= 0) // Either no dot or dot is at the beginning + return resourceName; + + // Replace dots before the extension with backslashes + string pathWithoutExtension = resourceName.Substring(0, lastDotIndex).Replace('.', '\\'); + string extension = resourceName.Substring(lastDotIndex); + + return pathWithoutExtension + extension; + } +} diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Light/HLSL.xshd b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Light/HLSL.xshd new file mode 100644 index 0000000..4c09b08 --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Light/HLSL.xshd @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + &<>~%^*()-+=!|\/{}[]:;"' , ? + + + + // + + + /* + */ + + + + + " + " + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Light/JavaScript.xshd b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Light/JavaScript.xshd index 3c06332..b684c9d 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Light/JavaScript.xshd +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Light/JavaScript.xshd @@ -1,6 +1,6 @@ - + diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Light/zzz-After-JavaScript-HTML.xshd b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Light/zzz-After-JavaScript-HTML.xshd index 64c9e10..9bfb26c 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Light/zzz-After-JavaScript-HTML.xshd +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/Syntax/Light/zzz-After-JavaScript-HTML.xshd @@ -1,15 +1,5 @@ - - diff --git a/QuickLook/Helpers/Updater.cs b/QuickLook/Helpers/Updater.cs index 76847d7..e8f20a2 100644 --- a/QuickLook/Helpers/Updater.cs +++ b/QuickLook/Helpers/Updater.cs @@ -82,7 +82,7 @@ internal class Updater private static void CollectAndShowReleaseNotes() { - Task.Run(() => + _ = Task.Run(() => { try {