123123
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
namespace ZelWiki.Engine.Library
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class Constants
|
||||
{
|
||||
public const string SoftBreak = "<!--SoftBreak-->"; //These will remain as \r\n in the final HTML.
|
||||
public const string HardBreak = "<!--HardBreak-->"; //These will remain as <br /> in the final HTML.
|
||||
public const string SoftBreak = "<!--SoftBreak-->";
|
||||
public const string HardBreak = "<!--HardBreak-->";
|
||||
|
||||
public enum WikiMatchType
|
||||
{
|
||||
@@ -23,22 +26,24 @@
|
||||
public enum HandlerResultInstruction
|
||||
{
|
||||
/// <summary>
|
||||
/// Does not process the match, allowing it to be processed by another handler.
|
||||
/// 不处理匹配,允许它由另一个处理程序处理
|
||||
/// </summary>
|
||||
Skip,
|
||||
|
||||
/// <summary>
|
||||
/// Removes any single trailing newline after match.
|
||||
/// 删除匹配后的任何单个尾随换行符
|
||||
/// </summary>
|
||||
TruncateTrailingLine,
|
||||
|
||||
/// <summary>
|
||||
/// Will not continue to process content in this block.
|
||||
/// 将不会继续处理此块中的内容
|
||||
/// </summary>
|
||||
DisallowNestedProcessing,
|
||||
|
||||
/// <summary>
|
||||
/// As opposed to the default functionality of replacing all matches, this will cause ony the first match to be replaced.
|
||||
/// This also means that each match will be processed individually, which can impact performance.
|
||||
///
|
||||
/// </summary>
|
||||
OnlyReplaceFirstMatch
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,16 @@
|
||||
namespace ZelWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles wiki comments. These are generally removed from the result.
|
||||
/// 处理评论.
|
||||
/// </summary>
|
||||
public interface 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
namespace ZelWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles wiki completion events.
|
||||
/// 处理完成事件
|
||||
/// </summary>
|
||||
public interface 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
namespace ZelWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles wiki emojis.
|
||||
/// emoji
|
||||
/// </summary>
|
||||
public interface 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
namespace ZelWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles exceptions thrown by the wiki engine.
|
||||
/// 错误日志
|
||||
/// </summary>
|
||||
public interface 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
namespace ZelWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles links the wiki to another site.
|
||||
///
|
||||
/// </summary>
|
||||
public interface 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,22 +3,23 @@
|
||||
namespace ZelWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Base function handler for standard, post-processing, scoped and processing-instruction functions.
|
||||
/// 处理函数.
|
||||
/// </summary>
|
||||
public interface IFunctionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a collection of function prototypes.
|
||||
/// 回调.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public FunctionPrototypeCollection Prototypes { get; }
|
||||
|
||||
/// <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">For scope functions, this is 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,18 @@
|
||||
namespace ZelWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles wiki headings. These are automatically added to the table of contents.
|
||||
/// 处理标题
|
||||
/// </summary>
|
||||
public interface 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,19 +3,21 @@
|
||||
namespace ZelWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles links from one wiki page to another.
|
||||
/// 处理内链
|
||||
/// </summary>
|
||||
public interface 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>
|
||||
public HandlerResult Handle(IZelEngineState state, NamespaceNavigation pageNavigation, string pageName, string linkText, string? image, int imageScale);
|
||||
/// <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>
|
||||
public HandlerResult Handle(IZelEngineState state, NamespaceNavigation pageNavigation, string pageName,
|
||||
string linkText, string? image, int imageScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
namespace ZelWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles basic markup/style instructions like bole, italic, underline, etc.
|
||||
/// 处理基本的标记/样式指令,如粗体、斜体、下划线等.
|
||||
/// </summary>
|
||||
public interface 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace ZelWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles post-processing function calls.
|
||||
///
|
||||
/// </summary>
|
||||
public interface IPostProcessingFunctionHandler : IFunctionHandler
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace ZelWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles processing-instruction function calls.
|
||||
///
|
||||
/// </summary>
|
||||
public interface IProcessingInstructionFunctionHandler : IFunctionHandler
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace ZelWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles scope function calls.
|
||||
///
|
||||
/// </summary>
|
||||
public interface IScopeFunctionHandler : IFunctionHandler
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace ZelWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles standard function calls.
|
||||
///
|
||||
/// </summary>
|
||||
public interface IStandardFunctionHandler : IFunctionHandler
|
||||
{
|
||||
|
||||
@@ -6,69 +6,64 @@ namespace ZelWiki.Engine.Library.Interfaces
|
||||
{
|
||||
public interface IZelEngineState
|
||||
{
|
||||
#region Parameters.
|
||||
#region 参数
|
||||
|
||||
ISessionState? Session { get; }
|
||||
IQueryCollection QueryString { get; }
|
||||
|
||||
IZelEngine Engine { get; }
|
||||
IPage Page { get; }
|
||||
int? Revision { get; }
|
||||
public ISessionState? Session { get; }
|
||||
public IQueryCollection QueryString { get; }
|
||||
public IZelEngine Engine { get; }
|
||||
public IPage Page { get; }
|
||||
public int? Revision { get; }
|
||||
public HashSet<Constants.WikiMatchType> OmitMatches { get; }
|
||||
public int NestDepth { get; } //Used for recursion.
|
||||
public int NestDepth { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region State.
|
||||
#region 状态
|
||||
|
||||
/// <summary>
|
||||
/// Custom page title set by a call to @@Title("...")
|
||||
/// </summary>
|
||||
public string? PageTitle { get; set; }
|
||||
|
||||
Dictionary<string, string> Variables { get; }
|
||||
Dictionary<string, string> Snippets { get; }
|
||||
List<string> Tags { get; set; }
|
||||
List<string> ProcessingInstructions { get; }
|
||||
List<PageReference> OutgoingLinks { get; }
|
||||
List<TableOfContentsTag> TableOfContents { get; }
|
||||
List<string> Headers { get; }
|
||||
public Dictionary<string, string> Variables { get; }
|
||||
public Dictionary<string, string> Snippets { get; }
|
||||
public List<string> Tags { get; set; }
|
||||
public List<string> ProcessingInstructions { get; }
|
||||
public List<PageReference> OutgoingLinks { get; }
|
||||
public List<TableOfContentsTag> TableOfContents { get; }
|
||||
public List<string> Headers { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Results.
|
||||
#region 结果
|
||||
|
||||
string HtmlResult { get; }
|
||||
TimeSpan ProcessingTime { get; }
|
||||
int ErrorCount { get; }
|
||||
int MatchCount { get; }
|
||||
public string HtmlResult { get; }
|
||||
public TimeSpan ProcessingTime { get; }
|
||||
public int ErrorCount { get; }
|
||||
public int MatchCount { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Used to store values for handlers that needs to survive only a single wiki processing session.
|
||||
///
|
||||
/// </summary>
|
||||
public void SetStateValue<T>(string key, T value);
|
||||
|
||||
/// <summary>
|
||||
/// Used to get values for handlers that needs to survive only a single wiki processing session.
|
||||
///
|
||||
/// </summary>
|
||||
public bool TryGetStateValue<T>(string key, [MaybeNullWhen(false)] out T? outValue);
|
||||
|
||||
/// <summary>
|
||||
/// Used to get values for handlers that needs to survive only a single wiki processing session.
|
||||
///
|
||||
/// </summary>
|
||||
public T GetStateValue<T>(string key, T defaultValue);
|
||||
|
||||
string GetNextQueryToken();
|
||||
|
||||
/// <summary>
|
||||
/// Transforms "included" wiki pages, for example if a wiki function
|
||||
/// injected additional wiki markup, this 'could' be processed separately.
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="page">The child page to process</param>
|
||||
/// <param name="revision">The optional revision of the child page to process</param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="revision"></param>
|
||||
/// <returns></returns>
|
||||
IZelEngineState TransformChild(IPage page, int? revision = null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,27 +2,33 @@
|
||||
{
|
||||
public class PageReference
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the page. Such as "Sand Box" or "Some Namespace : SandBox".
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The namespace part of the Name.
|
||||
/// </summary>
|
||||
public string Namespace { get; set; } = string.Empty;
|
||||
|
||||
/// The cleaned up version of the name, safe for passing in URLs.
|
||||
public string Navigation { get; set; } = string.Empty;
|
||||
|
||||
public PageReference()
|
||||
{
|
||||
Name = string.Empty;
|
||||
Namespace = string.Empty;
|
||||
Navigation = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Namespace { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Navigation { get; set; }
|
||||
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is PageReference other
|
||||
&& string.Equals(Navigation, other.Navigation, StringComparison.OrdinalIgnoreCase);
|
||||
&& string.Equals(Navigation, other.Navigation, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
@@ -30,6 +36,12 @@
|
||||
return Navigation.GetHashCode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="navigation"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public PageReference(string name, string navigation)
|
||||
{
|
||||
var parts = name.Split("::");
|
||||
@@ -45,10 +57,10 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid page name {name}");
|
||||
throw new Exception($"页面名称无效: {name}");
|
||||
}
|
||||
|
||||
Navigation = navigation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace ZelWiki.Engine.Library
|
||||
{
|
||||
/// <summary>
|
||||
/// Table of contents tag.
|
||||
///
|
||||
/// </summary>
|
||||
public class TableOfContentsTag
|
||||
{
|
||||
@@ -10,6 +10,13 @@
|
||||
public string Text;
|
||||
public int StartingPosition;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="level"></param>
|
||||
/// <param name="startingPosition"></param>
|
||||
/// <param name="hrefTag"></param>
|
||||
/// <param name="text"></param>
|
||||
public TableOfContentsTag(int level, int startingPosition, string hrefTag, string text)
|
||||
{
|
||||
Level = level;
|
||||
|
||||
Reference in New Issue
Block a user