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

@@ -5,7 +5,7 @@ using ZelWiki.Models;
namespace ZelWiki.Engine
{
/// <summary>
/// Tiny wikifier (reduced feature-set) for things like comments and profile bios.
///
/// </summary>
public class WikifierLite
{
@@ -17,9 +17,9 @@ namespace ZelWiki.Engine
return string.Empty;
}
for (int i = 0; i < 100; i++) //We don't want to process nested wiki forever.
for (var i = 0; i < 100; i++)
{
bool processedMatches = false;
var processedMatches = false;
var matchStore = new Dictionary<string, string>();
var content = new WikiString(unprocessedText);
@@ -75,7 +75,8 @@ namespace ZelWiki.Engine
{
if (scale != 100 && scale > 0 && scale <= 500)
{
var emojiImage = $"<img src=\"/file/Emoji/{key.Trim('%')}?Scale={scale}\" alt=\"{emoji?.Name}\" />";
var emojiImage =
$"<img src=\"/file/Emoji/{key.Trim('%')}?Scale={scale}\" alt=\"{emoji?.Name}\" />";
pageContent.Replace(match.Value, StoreMatch(matchStore, emojiImage));
}
else
@@ -92,7 +93,7 @@ namespace ZelWiki.Engine
}
/// <summary>
/// Transform basic markup such as bold, italics, underline, etc. for single and multi-line.
/// 转换单行和多行的基本标记,如粗体、斜体、下划线等.
/// </summary>
/// <param name="pageContent"></param>
private static void TransformMarkup(WikiString pageContent, Dictionary<string, string> matchStore)
@@ -126,12 +127,12 @@ namespace ZelWiki.Engine
}
/// <summary>
/// Transform links, these can be internal Wiki links or external links.
/// 转换链接这些链接可以是内部Wiki链接或外部链接.
/// </summary>
/// <param name="pageContent"></param>
private static void TransformLinks(WikiString pageContent, Dictionary<string, string> matchStore)
{
//Parse external explicit links. eg. [[http://test.net]].
//解析外部链接 [[http://test.net]].
var rgx = new Regex(@"(\[\[http\:\/\/.+?\]\])", RegexOptions.IgnoreCase);
var matches = WikiUtility.OrderMatchesByLengthDescending(rgx.Matches(pageContent.ToString()));
foreach (var match in matches)
@@ -149,7 +150,7 @@ namespace ZelWiki.Engine
}
}
//Parse external explicit links. eg. [[https://test.net]].
//解析外部链接. [[https://test.net]].
rgx = new Regex(@"(\[\[https\:\/\/.+?\]\])", RegexOptions.IgnoreCase);
matches = WikiUtility.OrderMatchesByLengthDescending(rgx.Matches(pageContent.ToString()));
foreach (var match in matches)
@@ -167,7 +168,7 @@ namespace ZelWiki.Engine
}
}
//Parse internal dynamic links. eg [[AboutUs|About Us]].
//解析内部链接 [[AboutUs|About Us]].
rgx = new Regex(@"(\[\[.+?\]\])", RegexOptions.IgnoreCase);
matches = WikiUtility.OrderMatchesByLengthDescending(rgx.Matches(pageContent.ToString()));
foreach (var match in matches)
@@ -177,13 +178,15 @@ namespace ZelWiki.Engine
if (args.Count == 1)
{
pageContent.Replace(match.Value, StoreMatch(matchStore, $"<a href=\"{GlobalConfiguration.BasePath}/{args[0]}\">{args[0]}</a>"));
pageContent.Replace(match.Value,
StoreMatch(matchStore, $"<a href=\"{GlobalConfiguration.BasePath}/{args[0]}\">{args[0]}</a>"));
}
else if (args.Count > 1)
{
pageContent.Replace(match.Value, StoreMatch(matchStore, $"<a href=\"{GlobalConfiguration.BasePath}/{args[0]}\">{args[1]}</a>"));
pageContent.Replace(match.Value,
StoreMatch(matchStore, $"<a href=\"{GlobalConfiguration.BasePath}/{args[0]}\">{args[1]}</a>"));
}
}
}
}
}
}