Fix highlighting name
Some checks are pending
MSBuild / build (push) Waiting to run
MSBuild / publish (push) Blocked by required conditions

This commit is contained in:
ema
2025-05-26 05:42:27 +08:00
parent b81b2f9ef8
commit 6deadf9d73
5 changed files with 126 additions and 13 deletions

View File

@@ -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
{
/// <summary>
/// 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"
/// </summary>
/// <param name="resourceName">The embedded resource name (excluding the default namespace).</param>
/// <returns>A string representing the resource as a dummy file path.</returns>
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;
}
}