This commit is contained in:
Zel
2025-02-23 18:47:21 +08:00
parent eaaffeeccb
commit e46a7ca31c
104 changed files with 2630 additions and 2516 deletions

View File

@@ -3,6 +3,9 @@ using System.Text.RegularExpressions;
namespace ZelWiki.Library
{
/// <summary>
/// 导航
/// </summary>
public class Navigation
{
public static string Clean(string? str)
@@ -11,30 +14,26 @@ namespace ZelWiki.Library
{
return string.Empty;
}
//Fix names like "::Page" or "Namespace::".
str = str.Trim().Trim([':']).Trim();
if (str.Contains("::"))
{
throw new Exception("Navigation can not contain a namespace.");
throw new Exception("导航不能包含命名空间");
}
// Decode common HTML entities
str = str.Replace("&quot;", "\"")
.Replace("&amp;", "&")
.Replace("&lt;", "<")
.Replace("&gt;", ">")
.Replace("&nbsp;", " ");
// Normalize backslashes to forward slashes
str = str.Replace('\\', '/');
// Replace special sequences
str = str.Replace("::", "_").Trim();
var sb = new StringBuilder();
foreach (char c in str)
foreach (var c in str)
{
if (char.IsWhiteSpace(c) || c == '.')
{
@@ -46,9 +45,8 @@ namespace ZelWiki.Library
}
}
string result = sb.ToString();
var result = sb.ToString();
// Remove multiple consecutive underscores or slashes
result = Regex.Replace(result, @"[_]{2,}", "_");
result = Regex.Replace(result, @"[/]{2,}", "/");