123123
This commit is contained in:
@@ -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] };
|
||||
|
||||
Reference in New Issue
Block a user