123123
This commit is contained in:
@@ -2,8 +2,13 @@
|
||||
{
|
||||
public class AggregatedSearchToken
|
||||
{
|
||||
public string Token { get; set; } = string.Empty;
|
||||
public AggregatedSearchToken()
|
||||
{
|
||||
Token = string.Empty;
|
||||
DoubleMetaphone = string.Empty;
|
||||
}
|
||||
public string Token { get; set; }
|
||||
public double Weight { get; set; }
|
||||
public string DoubleMetaphone { get; set; } = string.Empty;
|
||||
public string DoubleMetaphone { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,19 @@ using ZelWiki.Engine.Library.Interfaces;
|
||||
namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles wiki comments. These are generally removed from the result.
|
||||
///
|
||||
/// </summary>
|
||||
public class CommentHandler : ICommentHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles a wiki comment.
|
||||
/// 处理评论
|
||||
/// </summary>
|
||||
/// <param name="state">Reference to the wiki state object</param>
|
||||
/// <param name="text">The comment text</param>
|
||||
/// <param name="state"></param>
|
||||
/// <param name="text"></param>
|
||||
/// <returns></returns>
|
||||
public HandlerResult Handle(IZelEngineState state, string text)
|
||||
{
|
||||
return new HandlerResult() { Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine] };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,14 @@ using ZelWiki.Repository;
|
||||
namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles wiki completion events.
|
||||
///
|
||||
/// </summary>
|
||||
public class CompletionHandler : ICompletionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles wiki completion events. Is called when the wiki processing competes for a given page.
|
||||
/// 完成事件
|
||||
/// </summary>
|
||||
/// <param name="state">Reference to the wiki state object</param>
|
||||
/// <param name="state"></param>
|
||||
public void Complete(IZelEngineState state)
|
||||
{
|
||||
if (GlobalConfiguration.RecordCompilationMetrics)
|
||||
@@ -28,4 +28,4 @@ namespace ZelWiki.Engine.Implementation
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,17 @@ using ZelWiki.Models;
|
||||
namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles wiki emojis.
|
||||
///
|
||||
/// </summary>
|
||||
public class EmojiHandler : IEmojiHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles an emoji instruction.
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="state">Reference to the wiki state object</param>
|
||||
/// <param name="key">The lookup key for the given emoji.</param>
|
||||
/// <param name="scale">The desired 1-100 scale factor for the emoji.</param>
|
||||
/// <param name="state"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="scale"></param>
|
||||
/// <returns></returns>
|
||||
public HandlerResult Handle(IZelEngineState state, string key, int scale)
|
||||
{
|
||||
var emoji = GlobalConfiguration.Emojis.FirstOrDefault(o => o.Shortcut == key);
|
||||
@@ -23,21 +24,24 @@ namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
if (scale != 100 && scale > 0 && scale <= 500)
|
||||
{
|
||||
var emojiImage = $"<img src=\"{GlobalConfiguration.BasePath}/file/Emoji/{key.Trim('%')}?Scale={scale}\" alt=\"{emoji?.Name}\" />";
|
||||
var emojiImage =
|
||||
$"<img src=\"{GlobalConfiguration.BasePath}/file/Emoji/{key.Trim('%')}?Scale={scale}\" alt=\"{emoji?.Name}\" />";
|
||||
|
||||
return new HandlerResult(emojiImage);
|
||||
}
|
||||
else
|
||||
{
|
||||
var emojiImage = $"<img src=\"{GlobalConfiguration.BasePath}/file/Emoji/{key.Trim('%')}\" alt=\"{emoji?.Name}\" />";
|
||||
var emojiImage =
|
||||
$"<img src=\"{GlobalConfiguration.BasePath}/file/Emoji/{key.Trim('%')}\" alt=\"{emoji?.Name}\" />";
|
||||
|
||||
return new HandlerResult(emojiImage);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new HandlerResult(key) { Instructions = [Constants.HandlerResultInstruction.DisallowNestedProcessing] };
|
||||
return new HandlerResult(key)
|
||||
{ Instructions = [Constants.HandlerResultInstruction.DisallowNestedProcessing] };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,16 @@ using ZelWiki.Repository;
|
||||
namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles exceptions thrown by the wiki engine.
|
||||
/// 异常处理.
|
||||
/// </summary>
|
||||
public class ExceptionHandler : IExceptionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when an exception is thrown by the wiki engine.
|
||||
/// 日志处理
|
||||
/// </summary>
|
||||
/// <param name="state">Reference to the wiki state object</param>
|
||||
/// <param name="ex">Optional exception, in the case that this was an actual exception.</param>
|
||||
/// <param name="customText">Text that accompanies the exception.</param>
|
||||
/// <param name="state"></param>
|
||||
/// <param name="ex"></param>
|
||||
/// <param name="customText"></param>
|
||||
public void Log(IZelEngineState state, Exception? ex, string customText)
|
||||
{
|
||||
if (ex != null)
|
||||
@@ -24,4 +24,4 @@ namespace ZelWiki.Engine.Implementation
|
||||
ExceptionRepository.InsertException(customText);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,18 @@ using ZelWiki.Engine.Library.Interfaces;
|
||||
namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles links the wiki to another site.
|
||||
/// 处理链接
|
||||
/// </summary>
|
||||
public class ExternalLinkHandler : IExternalLinkHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles an internal wiki link.
|
||||
/// 处理内链
|
||||
/// </summary>
|
||||
/// <param name="state">Reference to the wiki state object</param>
|
||||
/// <param name="link">The address of the external site being linked to.</param>
|
||||
/// <param name="text">The text which should be show in the absence of an image.</param>
|
||||
/// <param name="image">The image that should be shown.</param>
|
||||
/// <param name="imageScale">The 0-100 image scale factor for the given image.</param>
|
||||
/// <param name="state"></param>
|
||||
/// <param name="link"></param>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="image"></param>
|
||||
/// <returns></returns>
|
||||
public HandlerResult Handle(IZelEngineState state, string link, string? text, string? image)
|
||||
{
|
||||
if (string.IsNullOrEmpty(image))
|
||||
@@ -25,13 +25,11 @@ namespace ZelWiki.Engine.Implementation
|
||||
Instructions = [Constants.HandlerResultInstruction.DisallowNestedProcessing]
|
||||
};
|
||||
}
|
||||
else
|
||||
|
||||
return new HandlerResult($"<a href=\"{link}\"><img src=\"{image}\" border =\"0\"></a>")
|
||||
{
|
||||
return new HandlerResult($"<a href=\"{link}\"><img src=\"{image}\" border =\"0\"></a>")
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.DisallowNestedProcessing]
|
||||
};
|
||||
}
|
||||
Instructions = [Constants.HandlerResultInstruction.DisallowNestedProcessing]
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,18 +3,16 @@ using ZelWiki.Engine.Library.Interfaces;
|
||||
|
||||
namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles wiki headings. These are automatically added to the table of contents.
|
||||
/// </summary>
|
||||
public class HeadingHandler : IHeadingHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles wiki headings. These are automatically added to the table of contents.
|
||||
/// 处理白哦提
|
||||
/// </summary>
|
||||
/// <param name="state">Reference to the wiki state object</param>
|
||||
/// <param name="depth">The size of the header, also used for table of table of contents indentation.</param>
|
||||
/// <param name="link">The self link reference.</param>
|
||||
/// <param name="text">The text for the self link.</param>
|
||||
/// <param name="state"></param>
|
||||
/// <param name="depth"></param>
|
||||
/// <param name="link"></param>
|
||||
/// <param name="text"></param>
|
||||
/// <returns></returns>
|
||||
public HandlerResult Handle(IZelEngineState state, int depth, string link, string text)
|
||||
{
|
||||
if (depth >= 2 && depth <= 6)
|
||||
@@ -22,11 +20,12 @@ namespace ZelWiki.Engine.Implementation
|
||||
int fontSize = 8 - depth;
|
||||
if (fontSize < 5) fontSize = 5;
|
||||
|
||||
string html = "<font size=\"" + fontSize + "\"><a name=\"" + link + "\"><span class=\"WikiH" + (depth - 1).ToString() + "\">" + text + "</span></a></font>\r\n";
|
||||
string html = "<font size=\"" + fontSize + "\"><a name=\"" + link + "\"><span class=\"WikiH" +
|
||||
(depth - 1).ToString() + "\">" + text + "</span></a></font>\r\n";
|
||||
return new HandlerResult(html);
|
||||
}
|
||||
|
||||
return new HandlerResult() { Instructions = [Constants.HandlerResultInstruction.Skip] };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,41 +9,41 @@ using ZelWiki.Repository;
|
||||
|
||||
namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Inserts a new page if Page.Id == 0, other wise updates the page. All metadata is written to the database.
|
||||
/// 更新页面 如果Id为0则新增页面
|
||||
/// </summary>
|
||||
/// <param name="sessionState"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="wikifier"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="sessionState"></param>
|
||||
/// <returns></returns>
|
||||
public static int UpsertPage(IZelEngine wikifier, Page page, ISessionState? sessionState = null)
|
||||
{
|
||||
bool isNewlyCreated = page.Id == 0;
|
||||
var isNewlyCreated = page.Id == 0;
|
||||
|
||||
page.Id = PageRepository.SavePage(page);
|
||||
|
||||
RefreshPageMetadata(wikifier, page, sessionState);
|
||||
|
||||
if (isNewlyCreated)
|
||||
{
|
||||
//This will update the PageId of references that have been saved to the navigation link.
|
||||
PageRepository.UpdateSinglePageReference(page.Navigation, page.Id);
|
||||
}
|
||||
|
||||
|
||||
return page.Id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rebuilds the page and writes all aspects to the database.
|
||||
/// 重建页面并将所有方面写入数据库
|
||||
/// </summary>
|
||||
/// <param name="sessionState"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="wikifier"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="sessionState"></param>
|
||||
public static void RefreshPageMetadata(IZelEngine wikifier, Page page, ISessionState? sessionState = null)
|
||||
{
|
||||
//We omit function calls from the tokenization process because they are too dynamic for static searching.
|
||||
var state = wikifier.Transform(sessionState, page, null,
|
||||
[Constants.WikiMatchType.StandardFunction]);
|
||||
|
||||
@@ -51,13 +51,13 @@ namespace ZelWiki.Engine.Implementation
|
||||
PageRepository.UpdatePageProcessingInstructions(page.Id, state.ProcessingInstructions);
|
||||
|
||||
var pageTokens = ParsePageTokens(state).Select(o =>
|
||||
new PageToken
|
||||
{
|
||||
PageId = page.Id,
|
||||
Token = o.Token,
|
||||
DoubleMetaphone = o.DoubleMetaphone,
|
||||
Weight = o.Weight
|
||||
}).ToList();
|
||||
new PageToken
|
||||
{
|
||||
PageId = page.Id,
|
||||
Token = o.Token,
|
||||
DoubleMetaphone = o.DoubleMetaphone,
|
||||
Weight = o.Weight
|
||||
}).ToList();
|
||||
|
||||
PageRepository.SavePageSearchTokens(pageTokens);
|
||||
|
||||
@@ -67,7 +67,13 @@ namespace ZelWiki.Engine.Implementation
|
||||
WikiCache.ClearCategory(WikiCacheKey.Build(WikiCache.Category.Page, [page.Navigation]));
|
||||
}
|
||||
|
||||
public static List<AggregatedSearchToken> ParsePageTokens(IZelEngineState state)
|
||||
#region Private
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
/// <returns></returns>
|
||||
private static List<AggregatedSearchToken> ParsePageTokens(IZelEngineState state)
|
||||
{
|
||||
var parsedTokens = new List<WeightedSearchToken>();
|
||||
|
||||
@@ -86,7 +92,7 @@ namespace ZelWiki.Engine.Implementation
|
||||
return aggregatedTokens;
|
||||
}
|
||||
|
||||
internal static List<WeightedSearchToken> ComputeParsedPageTokens(string content, double weightMultiplier)
|
||||
private static List<WeightedSearchToken> ComputeParsedPageTokens(string content, double weightMultiplier)
|
||||
{
|
||||
var searchConfig = ConfigurationRepository.GetConfigurationEntryValuesByGroupName("Search");
|
||||
|
||||
@@ -117,14 +123,17 @@ namespace ZelWiki.Engine.Implementation
|
||||
tokens.RemoveAll(o => exclusionWords.Contains(o));
|
||||
|
||||
var searchTokens = (from w in tokens
|
||||
group w by w into g
|
||||
select new WeightedSearchToken
|
||||
{
|
||||
Token = g.Key,
|
||||
Weight = g.Count() * weightMultiplier
|
||||
}).ToList();
|
||||
group w by w
|
||||
into g
|
||||
select new WeightedSearchToken
|
||||
{
|
||||
Token = g.Key,
|
||||
Weight = g.Count() * weightMultiplier
|
||||
}).ToList();
|
||||
|
||||
return searchTokens.Where(o => string.IsNullOrWhiteSpace(o.Token) == false).ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,19 +8,21 @@ using Constants = ZelWiki.Engine.Library.Constants;
|
||||
namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles links from one wiki page to another.
|
||||
/// 内链处理.
|
||||
/// </summary>
|
||||
public class InternalLinkHandler : IInternalLinkHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles an internal wiki link.
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="state">Reference to the wiki state object</param>
|
||||
/// <param name="pageNavigation">The navigation for the linked page.</param>
|
||||
/// <param name="pageName">The name of the page being linked to.</param>
|
||||
/// <param name="linkText">The text which should be show in the absence of an image.</param>
|
||||
/// <param name="image">The image that should be shown.</param>
|
||||
/// <param name="imageScale">The 0-100 image scale factor for the given image.</param>
|
||||
/// <param name="state"></param>
|
||||
/// <param name="pageNavigation"></param>
|
||||
/// <param name="pageName"></param>
|
||||
/// <param name="linkText"></param>
|
||||
/// <param name="image"></param>
|
||||
/// <param name="imageScale"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public HandlerResult Handle(IZelEngineState state, NamespaceNavigation pageNavigation,
|
||||
string pageName, string linkText, string? image, int imageScale)
|
||||
{
|
||||
@@ -37,18 +39,21 @@ namespace ZelWiki.Engine.Implementation
|
||||
if (image.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase)
|
||||
|| image.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
//The image is external.
|
||||
href = $"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\"><img src=\"{GlobalConfiguration.BasePath}{image}?Scale={imageScale}\" /></a>";
|
||||
//外部图片.
|
||||
href =
|
||||
$"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\"><img src=\"{GlobalConfiguration.BasePath}{image}?Scale={imageScale}\" /></a>";
|
||||
}
|
||||
else if (image.Contains('/'))
|
||||
{
|
||||
//The image is located on another page.
|
||||
href = $"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\"><img src=\"{GlobalConfiguration.BasePath}/Page/Image/{image}?Scale={imageScale}\" /></a>";
|
||||
//图像位于另一页面.
|
||||
href =
|
||||
$"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\"><img src=\"{GlobalConfiguration.BasePath}/Page/Image/{image}?Scale={imageScale}\" /></a>";
|
||||
}
|
||||
else
|
||||
{
|
||||
//The image is located on this page, but this page does not exist.
|
||||
href = $"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\">{linkText}</a>";
|
||||
//图像位于此页面上,但此页面不存在.
|
||||
href =
|
||||
$"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\">{linkText}</a>";
|
||||
}
|
||||
|
||||
return new HandlerResult(href)
|
||||
@@ -58,7 +63,8 @@ namespace ZelWiki.Engine.Implementation
|
||||
}
|
||||
else if (linkText != null)
|
||||
{
|
||||
var href = $"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\">{linkText}</a>"
|
||||
var href =
|
||||
$"<a href=\"{GlobalConfiguration.BasePath}/Page/Create?Name={pageName}\">{linkText}</a>"
|
||||
+ "<font color=\"#cc0000\" size=\"2\">?</font>";
|
||||
|
||||
return new HandlerResult(href)
|
||||
@@ -73,7 +79,7 @@ namespace ZelWiki.Engine.Implementation
|
||||
}
|
||||
else
|
||||
{
|
||||
//The page does not exist and the user does not have permission to create it.
|
||||
//该页面不存在,用户没有创建该页面的权限.
|
||||
|
||||
if (image != null)
|
||||
{
|
||||
@@ -82,17 +88,18 @@ namespace ZelWiki.Engine.Implementation
|
||||
if (image.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase)
|
||||
|| image.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
//The image is external.
|
||||
//外部图像.
|
||||
mockHref = $"<img src=\"{GlobalConfiguration.BasePath}{image}?Scale={imageScale}\" />";
|
||||
}
|
||||
else if (image.Contains('/'))
|
||||
{
|
||||
//The image is located on another page.
|
||||
mockHref = $"<img src=\"{GlobalConfiguration.BasePath}/Page/Image/{image}?Scale={imageScale}\" />";
|
||||
//图像位于另一页.
|
||||
mockHref =
|
||||
$"<img src=\"{GlobalConfiguration.BasePath}/Page/Image/{image}?Scale={imageScale}\" />";
|
||||
}
|
||||
else
|
||||
{
|
||||
//The image is located on this page, but this page does not exist.
|
||||
//图像位于此页面上,但此页面不存在.
|
||||
mockHref = $"linkText";
|
||||
}
|
||||
|
||||
@@ -110,7 +117,7 @@ namespace ZelWiki.Engine.Implementation
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("No link or image was specified.");
|
||||
throw new Exception("未指定链接或图像.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,23 +130,26 @@ namespace ZelWiki.Engine.Implementation
|
||||
if (image.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase)
|
||||
|| image.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
//The image is external.
|
||||
href = $"<a href=\"{GlobalConfiguration.BasePath}/{page.Navigation}\"><img src=\"{GlobalConfiguration.BasePath}{image}\" /></a>";
|
||||
//外部图像.
|
||||
href =
|
||||
$"<a href=\"{GlobalConfiguration.BasePath}/{page.Navigation}\"><img src=\"{GlobalConfiguration.BasePath}{image}\" /></a>";
|
||||
}
|
||||
else if (image.Contains('/'))
|
||||
{
|
||||
//The image is located on another page.
|
||||
href = $"<a href=\"{GlobalConfiguration.BasePath}/{page.Navigation}\"><img src=\"{GlobalConfiguration.BasePath}/Page/Image/{image}?Scale={imageScale}\" /></a>";
|
||||
//图像在另一页面.
|
||||
href =
|
||||
$"<a href=\"{GlobalConfiguration.BasePath}/{page.Navigation}\"><img src=\"{GlobalConfiguration.BasePath}/Page/Image/{image}?Scale={imageScale}\" /></a>";
|
||||
}
|
||||
else
|
||||
{
|
||||
//The image is located on this page.
|
||||
href = $"<a href=\"{GlobalConfiguration.BasePath}/{page.Navigation}\"><img src=\"{GlobalConfiguration.BasePath}/Page/Image/{state.Page.Navigation}/{image}?Scale={imageScale}\" /></a>";
|
||||
//图像在此页面
|
||||
href =
|
||||
$"<a href=\"{GlobalConfiguration.BasePath}/{page.Navigation}\"><img src=\"{GlobalConfiguration.BasePath}/Page/Image/{state.Page.Navigation}/{image}?Scale={imageScale}\" /></a>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Just a plain ol' internal page link.
|
||||
//内链
|
||||
href = $"<a href=\"{GlobalConfiguration.BasePath}/{page.Navigation}\">{linkText}</a>";
|
||||
}
|
||||
|
||||
@@ -150,4 +160,4 @@ namespace ZelWiki.Engine.Implementation
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,17 @@ using ZelWiki.Engine.Library.Interfaces;
|
||||
namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles basic markup/style instructions like bole, italic, underline, etc.
|
||||
/// 处理基本的标记/样式指令,如粗体、斜体、下划线等.
|
||||
/// </summary>
|
||||
public class MarkupHandler : IMarkupHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles basic markup instructions like bole, italic, underline, etc.
|
||||
/// 处理基本的标记指令,如粗体、斜体、下划线等
|
||||
/// </summary>
|
||||
/// <param name="state">Reference to the wiki state object</param>
|
||||
/// <param name="sequence">The sequence of symbols that were found to denotate this markup instruction,</param>
|
||||
/// <param name="scopeBody">The body of text to apply the style to.</param>
|
||||
/// <param name="state"></param>
|
||||
/// <param name="sequence"></param>
|
||||
/// <param name="scopeBody"></param>
|
||||
/// <returns></returns>
|
||||
public HandlerResult Handle(IZelEngineState state, char sequence, string scopeBody)
|
||||
{
|
||||
switch (sequence)
|
||||
@@ -26,8 +27,7 @@ namespace ZelWiki.Engine.Implementation
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return new HandlerResult() { Instructions = [Constants.HandlerResultInstruction.Skip] };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ using ZelWiki.Models;
|
||||
namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles post-processing function calls.
|
||||
/// 处理后处理函数调用.
|
||||
/// </summary>
|
||||
public class PostProcessingFunctionHandler : IPostProcessingFunctionHandler
|
||||
{
|
||||
@@ -20,9 +20,10 @@ namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
if (_collection == null)
|
||||
{
|
||||
_collection = new FunctionPrototypeCollection(FunctionPrototypeCollection.WikiFunctionType.Standard);
|
||||
_collection =
|
||||
new FunctionPrototypeCollection(FunctionPrototypeCollection.WikiFunctionType.Standard);
|
||||
|
||||
#region Prototypes.
|
||||
#region
|
||||
|
||||
_collection.Add("##Tags: <string>{styleName(Flat,List)}='List'");
|
||||
_collection.Add("##TagCloud: <string>[pageTag] | <integer>{Top}='1000'");
|
||||
@@ -37,133 +38,129 @@ namespace ZelWiki.Engine.Implementation
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called to handle function calls when proper prototypes are matched.
|
||||
/// 当匹配到合适的原型时,调用它来处理函数调用。
|
||||
/// </summary>
|
||||
/// <param name="state">Reference to the wiki state object</param>
|
||||
/// <param name="function">The parsed function call and all its parameters and their values.</param>
|
||||
/// <param name="scopeBody">This is not a scope function, this should always be null</param>
|
||||
/// <param name="state"></param>
|
||||
/// <param name="function"></param>
|
||||
/// <param name="scopeBody"></param>
|
||||
/// <returns></returns>
|
||||
public HandlerResult Handle(IZelEngineState state, FunctionCall function, string? scopeBody = null)
|
||||
{
|
||||
switch (function.Name.ToLower())
|
||||
{
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
//Displays a tag link list.
|
||||
case "tags": //##tags
|
||||
{
|
||||
var styleName = function.Parameters.Get<string>("styleName").ToLower();
|
||||
var html = new StringBuilder();
|
||||
|
||||
if (styleName == "list")
|
||||
{
|
||||
string styleName = function.Parameters.Get<string>("styleName").ToLower();
|
||||
var html = new StringBuilder();
|
||||
|
||||
if (styleName == "list")
|
||||
html.Append("<ul>");
|
||||
foreach (var tag in state.Tags)
|
||||
{
|
||||
html.Append("<ul>");
|
||||
foreach (var tag in state.Tags)
|
||||
{
|
||||
html.Append($"<li><a href=\"{GlobalConfiguration.BasePath}/Tag/Browse/{tag}\">{tag}</a>");
|
||||
}
|
||||
html.Append("</ul>");
|
||||
}
|
||||
else if (styleName == "flat")
|
||||
{
|
||||
foreach (var tag in state.Tags)
|
||||
{
|
||||
if (html.Length > 0) html.Append(" | ");
|
||||
html.Append($"<a href=\"{GlobalConfiguration.BasePath}/Tag/Browse/{tag}\">{tag}</a>");
|
||||
}
|
||||
html.Append($"<li><a href=\"{GlobalConfiguration.BasePath}/Tag/Browse/{tag}\">{tag}</a>");
|
||||
}
|
||||
|
||||
return new HandlerResult(html.ToString());
|
||||
html.Append("</ul>");
|
||||
}
|
||||
else if (styleName == "flat")
|
||||
{
|
||||
foreach (var tag in state.Tags)
|
||||
{
|
||||
if (html.Length > 0) html.Append(" | ");
|
||||
html.Append($"<a href=\"{GlobalConfiguration.BasePath}/Tag/Browse/{tag}\">{tag}</a>");
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
|
||||
case "tagcloud":
|
||||
{
|
||||
var top = function.Parameters.Get<int>("Top");
|
||||
string seedTag = function.Parameters.Get<string>("pageTag");
|
||||
{
|
||||
var top = function.Parameters.Get<int>("Top");
|
||||
string seedTag = function.Parameters.Get<string>("pageTag");
|
||||
|
||||
string html = TagCloud.Build(seedTag, top);
|
||||
return new HandlerResult(html);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
string html = TagCloud.Build(seedTag, top);
|
||||
return new HandlerResult(html);
|
||||
}
|
||||
|
||||
case "searchcloud":
|
||||
{
|
||||
var top = function.Parameters.Get<int>("Top");
|
||||
var tokens = function.Parameters.Get<string>("searchPhrase").Split(" ", StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
{
|
||||
var top = function.Parameters.Get<int>("Top");
|
||||
var tokens = function.Parameters.Get<string>("searchPhrase")
|
||||
.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
|
||||
string html = SearchCloud.Build(tokens, top);
|
||||
return new HandlerResult(html);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
//Displays a table of contents for the page based on the header tags.
|
||||
string html = SearchCloud.Build(tokens, top);
|
||||
return new HandlerResult(html);
|
||||
}
|
||||
|
||||
case "toc":
|
||||
{
|
||||
var alphabetized = function.Parameters.Get<bool>("alphabetized");
|
||||
|
||||
var html = new StringBuilder();
|
||||
|
||||
var tags = (from t in state.TableOfContents
|
||||
orderby t.StartingPosition
|
||||
select t).ToList();
|
||||
|
||||
var unordered = new List<TableOfContentsTag>();
|
||||
var ordered = new List<TableOfContentsTag>();
|
||||
|
||||
if (alphabetized)
|
||||
{
|
||||
bool alphabetized = function.Parameters.Get<bool>("alphabetized");
|
||||
|
||||
var html = new StringBuilder();
|
||||
|
||||
var tags = (from t in state.TableOfContents
|
||||
orderby t.StartingPosition
|
||||
select t).ToList();
|
||||
|
||||
var unordered = new List<TableOfContentsTag>();
|
||||
var ordered = new List<TableOfContentsTag>();
|
||||
|
||||
if (alphabetized)
|
||||
{
|
||||
int level = tags.FirstOrDefault()?.Level ?? 0;
|
||||
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
if (level != tag.Level)
|
||||
{
|
||||
ordered.AddRange(unordered.OrderBy(o => o.Text));
|
||||
unordered.Clear();
|
||||
level = tag.Level;
|
||||
}
|
||||
|
||||
unordered.Add(tag);
|
||||
}
|
||||
|
||||
ordered.AddRange(unordered.OrderBy(o => o.Text));
|
||||
unordered.Clear();
|
||||
|
||||
tags = ordered.ToList();
|
||||
}
|
||||
|
||||
int currentLevel = 0;
|
||||
var level = tags.FirstOrDefault()?.Level ?? 0;
|
||||
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
if (tag.Level > currentLevel)
|
||||
if (level != tag.Level)
|
||||
{
|
||||
while (currentLevel < tag.Level)
|
||||
{
|
||||
html.Append("<ul>");
|
||||
currentLevel++;
|
||||
}
|
||||
}
|
||||
else if (tag.Level < currentLevel)
|
||||
{
|
||||
while (currentLevel > tag.Level)
|
||||
{
|
||||
|
||||
html.Append("</ul>");
|
||||
currentLevel--;
|
||||
}
|
||||
ordered.AddRange(unordered.OrderBy(o => o.Text));
|
||||
unordered.Clear();
|
||||
level = tag.Level;
|
||||
}
|
||||
|
||||
html.Append("<li><a href=\"#" + tag.HrefTag + "\">" + tag.Text + "</a></li>");
|
||||
unordered.Add(tag);
|
||||
}
|
||||
|
||||
while (currentLevel > 0)
|
||||
{
|
||||
html.Append("</ul>");
|
||||
currentLevel--;
|
||||
}
|
||||
ordered.AddRange(unordered.OrderBy(o => o.Text));
|
||||
unordered.Clear();
|
||||
|
||||
return new HandlerResult(html.ToString());
|
||||
tags = ordered.ToList();
|
||||
}
|
||||
|
||||
var currentLevel = 0;
|
||||
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
if (tag.Level > currentLevel)
|
||||
{
|
||||
while (currentLevel < tag.Level)
|
||||
{
|
||||
html.Append("<ul>");
|
||||
currentLevel++;
|
||||
}
|
||||
}
|
||||
else if (tag.Level < currentLevel)
|
||||
{
|
||||
while (currentLevel > tag.Level)
|
||||
{
|
||||
html.Append("</ul>");
|
||||
currentLevel--;
|
||||
}
|
||||
}
|
||||
|
||||
html.Append("<li><a href=\"#" + tag.HrefTag + "\">" + tag.Text + "</a></li>");
|
||||
}
|
||||
|
||||
while (currentLevel > 0)
|
||||
{
|
||||
html.Append("</ul>");
|
||||
currentLevel--;
|
||||
}
|
||||
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
return new HandlerResult() { Instructions = [Constants.HandlerResultInstruction.Skip] };
|
||||
|
||||
@@ -5,7 +5,7 @@ using ZelWiki.Engine.Library.Interfaces;
|
||||
namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles processing-instruction function calls, these functions affect the way the page is processed, but are not directly replaced with text.
|
||||
/// 处理处理指令函数调用,这些函数会影响页面的处理方式,但不会直接替换为文本.
|
||||
/// </summary>
|
||||
public class ProcessingInstructionFunctionHandler : IProcessingInstructionFunctionHandler
|
||||
{
|
||||
@@ -17,11 +17,11 @@ namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
if (_collection == null)
|
||||
{
|
||||
_collection = new FunctionPrototypeCollection(FunctionPrototypeCollection.WikiFunctionType.Instruction);
|
||||
_collection =
|
||||
new FunctionPrototypeCollection(FunctionPrototypeCollection.WikiFunctionType.Instruction);
|
||||
|
||||
#region Prototypes.
|
||||
#region
|
||||
|
||||
//Processing instructions:
|
||||
_collection.Add("@@Deprecate:");
|
||||
_collection.Add("@@Protect:<bool>{isSilent}='false'");
|
||||
_collection.Add("@@Tags: <string:infinite>[pageTags]");
|
||||
@@ -42,163 +42,152 @@ namespace ZelWiki.Engine.Implementation
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called to handle function calls when proper prototypes are matched.
|
||||
/// 处理各种页面
|
||||
/// </summary>
|
||||
/// <param name="state">Reference to the wiki state object</param>
|
||||
/// <param name="function">The parsed function call and all its parameters and their values.</param>
|
||||
/// <param name="scopeBody">This is not a scope function, this should always be null</param>
|
||||
/// <param name="state"></param>
|
||||
/// <param name="function"></param>
|
||||
/// <param name="scopeBody"></param>
|
||||
/// <returns></returns>
|
||||
public HandlerResult Handle(IZelEngineState state, FunctionCall function, string? scopeBody = null)
|
||||
{
|
||||
switch (function.Name.ToLower())
|
||||
{
|
||||
//We check wikifierSession.Factory.CurrentNestLevel here because we don't want to include the processing instructions on any parent pages that are injecting this one.
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
//Associates tags with a page. These are saved with the page and can also be displayed.
|
||||
case "tags": //##tag(pipe|separated|list|of|tags)
|
||||
{
|
||||
var tags = function.Parameters.GetList<string>("pageTags");
|
||||
state.Tags.AddRange(tags);
|
||||
state.Tags = state.Tags.Distinct().ToList();
|
||||
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
var tags = function.Parameters.GetList<string>("pageTags");
|
||||
state.Tags.AddRange(tags);
|
||||
state.Tags = state.Tags.Distinct().ToList();
|
||||
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
case "title":
|
||||
{
|
||||
state.PageTitle = function.Parameters.Get<string>("pageTitle");
|
||||
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
state.PageTitle = function.Parameters.Get<string>("pageTitle");
|
||||
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
case "hidefooterlastmodified":
|
||||
{
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.HideFooterLastModified);
|
||||
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.HideFooterLastModified);
|
||||
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
case "hidefootercomments":
|
||||
{
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.HideFooterComments);
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.HideFooterComments);
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
case "nocache":
|
||||
{
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.NoCache);
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.NoCache);
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
case "deprecate":
|
||||
{
|
||||
if (state.NestDepth == 0)
|
||||
{
|
||||
if (state.NestDepth == 0)
|
||||
{
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.Deprecate);
|
||||
state.Headers.Add("<div class=\"alert alert-danger\">This page has been deprecated and will eventually be deleted.</div>");
|
||||
}
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.Deprecate);
|
||||
state.Headers.Add(
|
||||
"<div class=\"alert alert-danger\">此页面已被弃用,最终将被删除.</div>");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
case "protect":
|
||||
{
|
||||
if (state.NestDepth == 0)
|
||||
{
|
||||
if (state.NestDepth == 0)
|
||||
bool isSilent = function.Parameters.Get<bool>("isSilent");
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.Protect);
|
||||
if (isSilent == false)
|
||||
{
|
||||
bool isSilent = function.Parameters.Get<bool>("isSilent");
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.Protect);
|
||||
if (isSilent == false)
|
||||
{
|
||||
state.Headers.Add("<div class=\"alert alert-info\">This page has been protected and can not be changed by non-moderators.</div>");
|
||||
}
|
||||
state.Headers.Add(
|
||||
"<div class=\"alert alert-info\">此页面已受到保护,非版主无法更改.</div>");
|
||||
}
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
case "template":
|
||||
{
|
||||
if (state.NestDepth == 0)
|
||||
{
|
||||
if (state.NestDepth == 0)
|
||||
{
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.Template);
|
||||
state.Headers.Add("<div class=\"alert alert-secondary\">This page is a template and will not appear in indexes or glossaries.</div>");
|
||||
}
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.Template);
|
||||
state.Headers.Add(
|
||||
"<div class=\"alert alert-secondary\">此页面是一个模板,不会出现在索引或术语表中.</div>");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
case "review":
|
||||
{
|
||||
if (state.NestDepth == 0)
|
||||
{
|
||||
if (state.NestDepth == 0)
|
||||
{
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.Review);
|
||||
state.Headers.Add("<div class=\"alert alert-warning\">This page has been flagged for review, its content may be inaccurate.</div>");
|
||||
}
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.Review);
|
||||
state.Headers.Add(
|
||||
"<div class=\"alert alert-warning\">此页面已被标记为待审核,其内容可能不准确.</div>");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
case "include":
|
||||
{
|
||||
if (state.NestDepth == 0)
|
||||
{
|
||||
if (state.NestDepth == 0)
|
||||
{
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.Include);
|
||||
state.Headers.Add("<div class=\"alert alert-secondary\">This page is an include and will not appear in indexes or glossaries.</div>");
|
||||
}
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.Include);
|
||||
state.Headers.Add(
|
||||
"<div class=\"alert alert-secondary\">此页为包含页,不会出现在索引或术语表中.</div>");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
case "draft":
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
if (state.NestDepth == 0)
|
||||
{
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.Draft);
|
||||
state.Headers.Add("<div class=\"alert alert-warning\">This page is a draft and may contain incorrect information and/or experimental styling.</div>");
|
||||
}
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
case "draft":
|
||||
{
|
||||
if (state.NestDepth == 0)
|
||||
{
|
||||
state.ProcessingInstructions.Add(ZelWiki.Library.Constants.WikiInstruction.Draft);
|
||||
state.Headers.Add(
|
||||
"<div class=\"alert alert-warning\">本页为草稿,可能包含不正确的信息包括但不仅限于实验性样式.</div>");
|
||||
}
|
||||
|
||||
return new HandlerResult(string.Empty)
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.TruncateTrailingLine]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return new HandlerResult() { Instructions = [Constants.HandlerResultInstruction.Skip] };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using static ZelWiki.Engine.Library.Constants;
|
||||
namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Handled scope function calls.
|
||||
///处理作用域函数调用.
|
||||
/// </summary>
|
||||
public class ScopeFunctionHandler : IScopeFunctionHandler
|
||||
{
|
||||
@@ -23,17 +23,23 @@ namespace ZelWiki.Engine.Implementation
|
||||
{
|
||||
_collection = new FunctionPrototypeCollection(FunctionPrototypeCollection.WikiFunctionType.Scoped);
|
||||
|
||||
#region Prototypes.
|
||||
#region
|
||||
|
||||
_collection.Add("$$Code: <string>{language(auto,wiki,cpp,lua,graphql,swift,r,yaml,kotlin,scss,shell,vbnet,json,objectivec,perl,diff,wasm,php,xml,bash,csharp,css,go,ini,javascript,less,makefile,markdown,plaintext,python,python-repl,ruby,rust,sql,typescript)}='auto'");
|
||||
_collection.Add(
|
||||
"$$Code: <string>{language(auto,wiki,cpp,lua,graphql,swift,r,yaml,kotlin,scss,shell,vbnet,json,objectivec,perl,diff,wasm,php,xml,bash,csharp,css,go,ini,javascript,less,makefile,markdown,plaintext,python,python-repl,ruby,rust,sql,typescript)}='auto'");
|
||||
_collection.Add("$$Bullets: <string>{type(unordered,ordered)}='unordered'");
|
||||
_collection.Add("$$Order: <string>{direction(ascending,descending)}='ascending'");
|
||||
_collection.Add("$$Jumbotron:");
|
||||
_collection.Add("$$Callout: <string>{styleName(default,primary,secondary,success,info,warning,danger)}='default' | <string>{titleText}=''");
|
||||
_collection.Add("$$Background: <string>{styleName(default,primary,secondary,light,dark,success,info,warning,danger,muted)}='default'");
|
||||
_collection.Add("$$Foreground: <string>{styleName(default,primary,secondary,light,dark,success,info,warning,danger,muted)}='default'");
|
||||
_collection.Add("$$Alert: <string>{styleName(default,primary,secondary,light,dark,success,info,warning,danger)}='default' | <string>{titleText}=''");
|
||||
_collection.Add("$$Card: <string>{styleName(default,primary,secondary,light,dark,success,info,warning,danger)}='default' | <string>{titleText}=''");
|
||||
_collection.Add(
|
||||
"$$Callout: <string>{styleName(default,primary,secondary,success,info,warning,danger)}='default' | <string>{titleText}=''");
|
||||
_collection.Add(
|
||||
"$$Background: <string>{styleName(default,primary,secondary,light,dark,success,info,warning,danger,muted)}='default'");
|
||||
_collection.Add(
|
||||
"$$Foreground: <string>{styleName(default,primary,secondary,light,dark,success,info,warning,danger,muted)}='default'");
|
||||
_collection.Add(
|
||||
"$$Alert: <string>{styleName(default,primary,secondary,light,dark,success,info,warning,danger)}='default' | <string>{titleText}=''");
|
||||
_collection.Add(
|
||||
"$$Card: <string>{styleName(default,primary,secondary,light,dark,success,info,warning,danger)}='default' | <string>{titleText}=''");
|
||||
_collection.Add("$$Collapse: <string>{linkText}='Show'");
|
||||
_collection.Add("$$Table: <boolean>{hasBorder}='true' | <boolean>{isFirstRowHeader}='true'");
|
||||
_collection.Add("$$StripedTable: <boolean>{hasBorder}='true' | <boolean>{isFirstRowHeader}='true'");
|
||||
@@ -47,326 +53,308 @@ namespace ZelWiki.Engine.Implementation
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called to handle function calls when proper prototypes are matched.
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="state">Reference to the wiki state object</param>
|
||||
/// <param name="function">The parsed function call and all its parameters and their values.</param>
|
||||
/// <param name="scopeBody">The the text that the function is designed to affect.</param>
|
||||
/// <param name="state"></param>
|
||||
/// <param name="function"></param>
|
||||
/// <param name="scopeBody"></param>
|
||||
/// <returns></returns>
|
||||
public HandlerResult Handle(IZelEngineState state, FunctionCall function, string? scopeBody = null)
|
||||
{
|
||||
scopeBody.EnsureNotNull($"The function '{function.Name}' scope body can not be null");
|
||||
scopeBody.EnsureNotNull($"函数'{function.Name}'作用域主题为空");
|
||||
|
||||
switch (function.Name.ToLower())
|
||||
{
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
case "code":
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
var language = function.Parameters.Get<string>("language");
|
||||
if (string.IsNullOrEmpty(language) || language?.ToLower() == "auto")
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
string language = function.Parameters.Get<string>("language");
|
||||
if (string.IsNullOrEmpty(language) || language?.ToLower() == "auto")
|
||||
{
|
||||
html.Append($"<pre>");
|
||||
html.Append($"<code>{scopeBody.Replace("\r\n", "\n").Replace("\n", SoftBreak)}</code></pre>");
|
||||
}
|
||||
else
|
||||
{
|
||||
html.Append($"<pre class=\"language-{language}\">");
|
||||
html.Append($"<code>{scopeBody.Replace("\r\n", "\n").Replace("\n", SoftBreak)}</code></pre>");
|
||||
}
|
||||
|
||||
return new HandlerResult(html.ToString())
|
||||
{
|
||||
Instructions = [Constants.HandlerResultInstruction.DisallowNestedProcessing]
|
||||
};
|
||||
html.Append($"<pre>");
|
||||
html.Append($"<code>{scopeBody.Replace("\r\n", "\n").Replace("\n", SoftBreak)}</code></pre>");
|
||||
}
|
||||
else
|
||||
{
|
||||
html.Append($"<pre class=\"language-{language}\">");
|
||||
html.Append($"<code>{scopeBody.Replace("\r\n", "\n").Replace("\n", SoftBreak)}</code></pre>");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
return new HandlerResult(html.ToString())
|
||||
{
|
||||
Instructions = [HandlerResultInstruction.DisallowNestedProcessing]
|
||||
};
|
||||
}
|
||||
case "stripedtable":
|
||||
case "table":
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
var hasBorder = function.Parameters.Get<bool>("hasBorder");
|
||||
var isFirstRowHeader = function.Parameters.Get<bool>("isFirstRowHeader");
|
||||
|
||||
html.Append($"<table class=\"table");
|
||||
|
||||
if (function.Name.Equals("stripedtable", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
var hasBorder = function.Parameters.Get<bool>("hasBorder");
|
||||
var isFirstRowHeader = function.Parameters.Get<bool>("isFirstRowHeader");
|
||||
|
||||
html.Append($"<table class=\"table");
|
||||
|
||||
if (function.Name.Equals("stripedtable", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
html.Append(" table-striped");
|
||||
}
|
||||
if (hasBorder)
|
||||
{
|
||||
html.Append(" table-bordered");
|
||||
}
|
||||
|
||||
html.Append($"\">");
|
||||
|
||||
var lines = scopeBody.Split(['\n'], StringSplitOptions.RemoveEmptyEntries).Select(o => o.Trim()).Where(o => o.Length > 0);
|
||||
|
||||
int rowNumber = 0;
|
||||
|
||||
foreach (var lineText in lines)
|
||||
{
|
||||
var columns = lineText.Split("||");
|
||||
|
||||
if (rowNumber == 0 && isFirstRowHeader)
|
||||
{
|
||||
html.Append($"<thead>");
|
||||
}
|
||||
else if (rowNumber == 1 && isFirstRowHeader || rowNumber == 0 && isFirstRowHeader == false)
|
||||
{
|
||||
html.Append($"<tbody>");
|
||||
}
|
||||
|
||||
html.Append($"<tr>");
|
||||
foreach (var columnText in columns)
|
||||
{
|
||||
if (rowNumber == 0 && isFirstRowHeader)
|
||||
{
|
||||
html.Append($"<td><strong>{columnText}</strong></td>");
|
||||
}
|
||||
else
|
||||
{
|
||||
html.Append($"<td>{columnText}</td>");
|
||||
}
|
||||
}
|
||||
|
||||
if (rowNumber == 0 && isFirstRowHeader)
|
||||
{
|
||||
html.Append($"</thead>");
|
||||
}
|
||||
html.Append($"</tr>");
|
||||
|
||||
rowNumber++;
|
||||
}
|
||||
|
||||
html.Append($"</tbody>");
|
||||
html.Append($"</table>");
|
||||
|
||||
return new HandlerResult(html.ToString());
|
||||
html.Append(" table-striped");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
if (hasBorder)
|
||||
{
|
||||
html.Append(" table-bordered");
|
||||
}
|
||||
|
||||
html.Append($"\">");
|
||||
|
||||
var lines = scopeBody.Split(['\n'], StringSplitOptions.RemoveEmptyEntries).Select(o => o.Trim())
|
||||
.Where(o => o.Length > 0);
|
||||
|
||||
int rowNumber = 0;
|
||||
|
||||
foreach (var lineText in lines)
|
||||
{
|
||||
var columns = lineText.Split("||");
|
||||
|
||||
if (rowNumber == 0 && isFirstRowHeader)
|
||||
{
|
||||
html.Append($"<thead>");
|
||||
}
|
||||
else if (rowNumber == 1 && isFirstRowHeader || rowNumber == 0 && isFirstRowHeader == false)
|
||||
{
|
||||
html.Append($"<tbody>");
|
||||
}
|
||||
|
||||
html.Append($"<tr>");
|
||||
foreach (var columnText in columns)
|
||||
{
|
||||
if (rowNumber == 0 && isFirstRowHeader)
|
||||
{
|
||||
html.Append($"<td><strong>{columnText}</strong></td>");
|
||||
}
|
||||
else
|
||||
{
|
||||
html.Append($"<td>{columnText}</td>");
|
||||
}
|
||||
}
|
||||
|
||||
if (rowNumber == 0 && isFirstRowHeader)
|
||||
{
|
||||
html.Append($"</thead>");
|
||||
}
|
||||
|
||||
html.Append($"</tr>");
|
||||
|
||||
rowNumber++;
|
||||
}
|
||||
|
||||
html.Append($"</tbody>");
|
||||
html.Append($"</table>");
|
||||
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
case "bullets":
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
var type = function.Parameters.Get<string>("type");
|
||||
|
||||
if (type == "unordered")
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
var lines = scopeBody.Split(['\n'], StringSplitOptions.RemoveEmptyEntries).Select(o => o.Trim())
|
||||
.Where(o => o.Length > 0);
|
||||
|
||||
string type = function.Parameters.Get<string>("type");
|
||||
int currentLevel = 0;
|
||||
|
||||
if (type == "unordered")
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var lines = scopeBody.Split(['\n'], StringSplitOptions.RemoveEmptyEntries).Select(o => o.Trim()).Where(o => o.Length > 0);
|
||||
|
||||
int currentLevel = 0;
|
||||
|
||||
foreach (var line in lines)
|
||||
var newIndent = 0;
|
||||
for (; newIndent < line.Length && line[newIndent] == '>'; newIndent++)
|
||||
{
|
||||
int newIndent = 0;
|
||||
for (; newIndent < line.Length && line[newIndent] == '>'; newIndent++)
|
||||
{
|
||||
//Count how many '>' are at the start of the line.
|
||||
}
|
||||
newIndent++;
|
||||
|
||||
if (newIndent < currentLevel)
|
||||
{
|
||||
for (; currentLevel != newIndent; currentLevel--)
|
||||
{
|
||||
html.Append($"</ul>");
|
||||
}
|
||||
}
|
||||
else if (newIndent > currentLevel)
|
||||
{
|
||||
for (; currentLevel != newIndent; currentLevel++)
|
||||
{
|
||||
html.Append($"<ul>");
|
||||
}
|
||||
}
|
||||
|
||||
html.Append($"<li>{line.Trim(['>'])}</li>");
|
||||
//计算行开头有多少个“>”.
|
||||
}
|
||||
|
||||
for (; currentLevel > 0; currentLevel--)
|
||||
newIndent++;
|
||||
|
||||
if (newIndent < currentLevel)
|
||||
{
|
||||
html.Append($"</ul>");
|
||||
for (; currentLevel != newIndent; currentLevel--)
|
||||
{
|
||||
html.Append($"</ul>");
|
||||
}
|
||||
}
|
||||
else if (newIndent > currentLevel)
|
||||
{
|
||||
for (; currentLevel != newIndent; currentLevel++)
|
||||
{
|
||||
html.Append($"<ul>");
|
||||
}
|
||||
}
|
||||
|
||||
html.Append($"<li>{line.Trim(['>'])}</li>");
|
||||
}
|
||||
else if (type == "ordered")
|
||||
|
||||
for (; currentLevel > 0; currentLevel--)
|
||||
{
|
||||
var lines = scopeBody.Split(['\n'], StringSplitOptions.RemoveEmptyEntries).Select(o => o.Trim()).Where(o => o.Length > 0);
|
||||
|
||||
int currentLevel = 0;
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
int newIndent = 0;
|
||||
for (; newIndent < line.Length && line[newIndent] == '>'; newIndent++)
|
||||
{
|
||||
//Count how many '>' are at the start of the line.
|
||||
}
|
||||
newIndent++;
|
||||
|
||||
if (newIndent < currentLevel)
|
||||
{
|
||||
for (; currentLevel != newIndent; currentLevel--)
|
||||
{
|
||||
html.Append($"</ol>");
|
||||
}
|
||||
}
|
||||
else if (newIndent > currentLevel)
|
||||
{
|
||||
for (; currentLevel != newIndent; currentLevel++)
|
||||
{
|
||||
html.Append($"<ol>");
|
||||
}
|
||||
}
|
||||
|
||||
html.Append($"<li>{line.Trim(['>'])}</li>");
|
||||
}
|
||||
|
||||
for (; currentLevel > 0; currentLevel--)
|
||||
{
|
||||
html.Append($"</ol>");
|
||||
}
|
||||
html.Append($"</ul>");
|
||||
}
|
||||
}
|
||||
else if (type == "ordered")
|
||||
{
|
||||
var lines = scopeBody.Split(['\n'], StringSplitOptions.RemoveEmptyEntries).Select(o => o.Trim())
|
||||
.Where(o => o.Length > 0);
|
||||
|
||||
var currentLevel = 0;
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var newIndent = 0;
|
||||
for (; newIndent < line.Length && line[newIndent] == '>'; newIndent++)
|
||||
{
|
||||
//计算行开头有多少个“>”.
|
||||
}
|
||||
|
||||
newIndent++;
|
||||
|
||||
if (newIndent < currentLevel)
|
||||
{
|
||||
for (; currentLevel != newIndent; currentLevel--)
|
||||
{
|
||||
html.Append($"</ol>");
|
||||
}
|
||||
}
|
||||
else if (newIndent > currentLevel)
|
||||
{
|
||||
for (; currentLevel != newIndent; currentLevel++)
|
||||
{
|
||||
html.Append($"<ol>");
|
||||
}
|
||||
}
|
||||
|
||||
html.Append($"<li>{line.Trim(['>'])}</li>");
|
||||
}
|
||||
|
||||
for (; currentLevel > 0; currentLevel--)
|
||||
{
|
||||
html.Append($"</ol>");
|
||||
}
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
case "definesnippet":
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
var name = function.Parameters.Get<string>("name");
|
||||
|
||||
if (!state.Snippets.TryAdd(name, scopeBody))
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
string name = function.Parameters.Get<string>("name");
|
||||
|
||||
if (!state.Snippets.TryAdd(name, scopeBody))
|
||||
{
|
||||
state.Snippets[name] = scopeBody;
|
||||
}
|
||||
|
||||
return new HandlerResult(html.ToString());
|
||||
state.Snippets[name] = scopeBody;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
case "alert":
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
string titleText = function.Parameters.Get<string>("titleText");
|
||||
string style = function.Parameters.Get<string>("styleName").ToLower();
|
||||
style = style == "default" ? "" : $"alert-{style}";
|
||||
var titleText = function.Parameters.Get<string>("titleText");
|
||||
var style = function.Parameters.Get<string>("styleName").ToLower();
|
||||
style = style == "default" ? "" : $"alert-{style}";
|
||||
|
||||
if (!string.IsNullOrEmpty(titleText)) scopeBody = $"<h1>{titleText}</h1>{scopeBody}";
|
||||
html.Append($"<div class=\"alert {style}\">{scopeBody}</div>");
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
if (!string.IsNullOrEmpty(titleText)) scopeBody = $"<h1>{titleText}</h1>{scopeBody}";
|
||||
html.Append($"<div class=\"alert {style}\">{scopeBody}</div>");
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
|
||||
case "order":
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
string direction = function.Parameters.Get<string>("direction");
|
||||
var lines = scopeBody.Split("\n").Select(o => o.Trim()).ToList();
|
||||
var direction = function.Parameters.Get<string>("direction");
|
||||
var lines = scopeBody.Split("\n").Select(o => o.Trim()).ToList();
|
||||
|
||||
if (direction == "ascending")
|
||||
{
|
||||
html.Append(string.Join("\r\n", lines.OrderBy(o => o)));
|
||||
}
|
||||
else
|
||||
{
|
||||
html.Append(string.Join("\r\n", lines.OrderByDescending(o => o)));
|
||||
}
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
html.Append(direction == "ascending"
|
||||
? string.Join("\r\n", lines.OrderBy(o => o))
|
||||
: string.Join("\r\n", lines.OrderByDescending(o => o)));
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
case "jumbotron":
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
string titleText = function.Parameters.Get("titleText", "");
|
||||
html.Append($"<div class=\"mt-4 p-5 bg-secondary text-white rounded\">");
|
||||
if (!string.IsNullOrEmpty(titleText)) html.Append($"<h1>{titleText}</h1>");
|
||||
html.Append($"<p>{scopeBody}</p>");
|
||||
html.Append($"</div>");
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
var titleText = function.Parameters.Get("titleText", "");
|
||||
html.Append($"<div class=\"mt-4 p-5 bg-secondary text-white rounded\">");
|
||||
if (!string.IsNullOrEmpty(titleText)) html.Append($"<h1>{titleText}</h1>");
|
||||
html.Append($"<p>{scopeBody}</p>");
|
||||
html.Append($"</div>");
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
case "foreground":
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
var style = BGFGStyle.GetForegroundStyle(function.Parameters.Get("styleName", "default")).Swap();
|
||||
html.Append($"<p class=\"{style.ForegroundStyle} {style.BackgroundStyle}\">{scopeBody}</p>");
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
var style = BGFGStyle.GetForegroundStyle(function.Parameters.Get("styleName", "default")).Swap();
|
||||
html.Append($"<p class=\"{style.ForegroundStyle} {style.BackgroundStyle}\">{scopeBody}</p>");
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
case "background":
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
var style = BGFGStyle.GetBackgroundStyle(function.Parameters.Get("styleName", "default"));
|
||||
html.Append($"<div class=\"p-3 mb-2 {style.ForegroundStyle} {style.BackgroundStyle}\">{scopeBody}</div>");
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
var style = BGFGStyle.GetBackgroundStyle(function.Parameters.Get("styleName", "default"));
|
||||
html.Append(
|
||||
$"<div class=\"p-3 mb-2 {style.ForegroundStyle} {style.BackgroundStyle}\">{scopeBody}</div>");
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
case "collapse":
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
string linkText = function.Parameters.Get<string>("linktext");
|
||||
string uid = "A" + Guid.NewGuid().ToString().Replace("-", "");
|
||||
html.Append($"<a data-bs-toggle=\"collapse\" href=\"#{uid}\" role=\"button\" aria-expanded=\"false\" aria-controls=\"{uid}\">{linkText}</a>");
|
||||
html.Append($"<div class=\"collapse\" id=\"{uid}\">");
|
||||
html.Append($"<div class=\"card card-body\"><p class=\"card-text\">{scopeBody}</p></div></div>");
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
var linkText = function.Parameters.Get<string>("linktext");
|
||||
var uid = "A" + Guid.NewGuid().ToString().Replace("-", "");
|
||||
html.Append(
|
||||
$"<a data-bs-toggle=\"collapse\" href=\"#{uid}\" role=\"button\" aria-expanded=\"false\" aria-controls=\"{uid}\">{linkText}</a>");
|
||||
html.Append($"<div class=\"collapse\" id=\"{uid}\">");
|
||||
html.Append($"<div class=\"card card-body\"><p class=\"card-text\">{scopeBody}</p></div></div>");
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
case "callout":
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
string titleText = function.Parameters.Get<string>("titleText");
|
||||
string style = function.Parameters.Get<string>("styleName").ToLower();
|
||||
style = style == "default" ? "" : style;
|
||||
string titleText = function.Parameters.Get<string>("titleText");
|
||||
string style = function.Parameters.Get<string>("styleName").ToLower();
|
||||
style = style == "default" ? "" : style;
|
||||
|
||||
html.Append($"<div class=\"bd-callout bd-callout-{style}\">");
|
||||
if (string.IsNullOrWhiteSpace(titleText) == false) html.Append($"<h4>{titleText}</h4>");
|
||||
html.Append($"{scopeBody}");
|
||||
html.Append($"</div>");
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
html.Append($"<div class=\"bd-callout bd-callout-{style}\">");
|
||||
if (string.IsNullOrWhiteSpace(titleText) == false) html.Append($"<h4>{titleText}</h4>");
|
||||
html.Append($"{scopeBody}");
|
||||
html.Append($"</div>");
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
case "card":
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
string titleText = function.Parameters.Get<string>("titleText");
|
||||
var style = BGFGStyle.GetBackgroundStyle(function.Parameters.Get("styleName", "default"));
|
||||
var titleText = function.Parameters.Get<string>("titleText");
|
||||
var style = BGFGStyle.GetBackgroundStyle(function.Parameters.Get("styleName", "default"));
|
||||
|
||||
html.Append($"<div class=\"card {style.ForegroundStyle} {style.BackgroundStyle} mb-3\">");
|
||||
if (string.IsNullOrEmpty(titleText) == false)
|
||||
{
|
||||
html.Append($"<div class=\"card-header\">{titleText}</div>");
|
||||
}
|
||||
html.Append("<div class=\"card-body\">");
|
||||
html.Append($"<p class=\"card-text\">{scopeBody}</p>");
|
||||
html.Append("</div>");
|
||||
html.Append("</div>");
|
||||
return new HandlerResult(html.ToString());
|
||||
|
||||
}
|
||||
html.Append($"<div class=\"card {style.ForegroundStyle} {style.BackgroundStyle} mb-3\">");
|
||||
if (string.IsNullOrEmpty(titleText) == false)
|
||||
html.Append($"<div class=\"card-header\">{titleText}</div>");
|
||||
|
||||
html.Append("<div class=\"card-body\">");
|
||||
html.Append($"<p class=\"card-text\">{scopeBody}</p>");
|
||||
html.Append("</div>");
|
||||
html.Append("</div>");
|
||||
return new HandlerResult(html.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
return new HandlerResult() { Instructions = [Constants.HandlerResultInstruction.Skip] };
|
||||
return new HandlerResult() { Instructions = [HandlerResultInstruction.Skip] };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,8 +2,14 @@
|
||||
{
|
||||
public class BGFGStyle
|
||||
{
|
||||
public string ForegroundStyle { get; set; } = String.Empty;
|
||||
public string BackgroundStyle { get; set; } = String.Empty;
|
||||
public BGFGStyle()
|
||||
{
|
||||
ForegroundStyle = string.Empty;
|
||||
BackgroundStyle = string.Empty;
|
||||
}
|
||||
|
||||
public string ForegroundStyle { get; set; }
|
||||
public string BackgroundStyle { get; set; }
|
||||
|
||||
public BGFGStyle(string foregroundStyle, string backgroundStyle)
|
||||
{
|
||||
@@ -16,9 +22,6 @@
|
||||
return new BGFGStyle(BackgroundStyle, ForegroundStyle);
|
||||
}
|
||||
|
||||
public BGFGStyle()
|
||||
{
|
||||
}
|
||||
|
||||
public static readonly Dictionary<string, BGFGStyle> ForegroundStyles = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
@@ -67,4 +70,4 @@
|
||||
return new BGFGStyle();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace ZelWiki.Engine.Implementation.Utility
|
||||
public static class Differentiator
|
||||
{
|
||||
/// <summary>
|
||||
/// This leaves a lot to be desired.
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="thisRev"></param>
|
||||
/// <param name="prevRev"></param>
|
||||
@@ -16,35 +16,35 @@ namespace ZelWiki.Engine.Implementation.Utility
|
||||
|
||||
var thisRevLines = thisRev.Split('\n');
|
||||
var prevRevLines = prevRev.Split('\n');
|
||||
int thisRevLineCount = thisRevLines.Length;
|
||||
int prevRevLinesCount = prevRevLines.Length;
|
||||
var thisRevLineCount = thisRevLines.Length;
|
||||
var prevRevLinesCount = prevRevLines.Length;
|
||||
|
||||
int linesAdded = prevRevLines.Except(thisRevLines).Count();
|
||||
int linesDeleted = thisRevLines.Except(prevRevLines).Count();
|
||||
var linesAdded = prevRevLines.Except(thisRevLines).Count();
|
||||
var linesDeleted = thisRevLines.Except(prevRevLines).Count();
|
||||
|
||||
if (thisRevLineCount != prevRevLinesCount)
|
||||
{
|
||||
summary.Append($"{Math.Abs(thisRevLineCount - prevRevLinesCount):N0} lines changed.");
|
||||
summary.Append($"{Math.Abs(thisRevLineCount - prevRevLinesCount):N0} 行修改.");
|
||||
}
|
||||
|
||||
if (linesAdded > 0)
|
||||
{
|
||||
if (summary.Length > 0) summary.Append(' ');
|
||||
summary.Append($"{linesAdded:N0} lines added.");
|
||||
summary.Append($"{linesAdded:N0} 行新增.");
|
||||
}
|
||||
|
||||
if (linesDeleted > 0)
|
||||
{
|
||||
if (summary.Length > 0) summary.Append(' ');
|
||||
summary.Append($"{linesDeleted:N0} lines deleted.");
|
||||
summary.Append($"{linesDeleted:N0} 行删除.");
|
||||
}
|
||||
|
||||
if (summary.Length == 0)
|
||||
{
|
||||
summary.Append($"No changes detected.");
|
||||
summary.Append($"未修改.");
|
||||
}
|
||||
|
||||
return summary.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,10 +16,10 @@ namespace ZelWiki.Engine.Implementation.Utility
|
||||
pages = pages.Take((int)maxCount).ToList();
|
||||
}
|
||||
|
||||
int pageCount = pages.Count;
|
||||
int fontSize = 7;
|
||||
int sizeStep = (pageCount > fontSize ? pageCount : (fontSize * 2)) / fontSize;
|
||||
int pageIndex = 0;
|
||||
var pageCount = pages.Count;
|
||||
var fontSize = 7;
|
||||
var sizeStep = (pageCount > fontSize ? pageCount : (fontSize * 2)) / fontSize;
|
||||
var pageIndex = 0;
|
||||
|
||||
var pageList = new List<TagCloudItem>();
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ namespace ZelWiki.Engine.Implementation.Utility
|
||||
tags = tags.Take((int)maxCount).ToList();
|
||||
}
|
||||
|
||||
int tagCount = tags.Count;
|
||||
int fontSize = 7;
|
||||
int sizeStep = (tagCount > fontSize ? tagCount : (fontSize * 2)) / fontSize;
|
||||
int tagIndex = 0;
|
||||
var tagCount = tags.Count;
|
||||
var fontSize = 7;
|
||||
var sizeStep = (tagCount > fontSize ? tagCount : (fontSize * 2)) / fontSize;
|
||||
var tagIndex = 0;
|
||||
|
||||
var tagList = new List<TagCloudItem>();
|
||||
|
||||
|
||||
@@ -2,7 +2,14 @@
|
||||
{
|
||||
public class WeightedSearchToken
|
||||
{
|
||||
public string Token { get; set; } = string.Empty;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public WeightedSearchToken()
|
||||
{
|
||||
Token = string.Empty;
|
||||
}
|
||||
public string Token { get; set; }
|
||||
public double Weight { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user