添加项目文件。
This commit is contained in:
44
TightWiki.Engine.Library/Constants.cs
Normal file
44
TightWiki.Engine.Library/Constants.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
namespace TightWiki.Engine.Library
|
||||
{
|
||||
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 enum WikiMatchType
|
||||
{
|
||||
ScopeFunction,
|
||||
Emoji,
|
||||
Instruction,
|
||||
Comment,
|
||||
Variable,
|
||||
Markup,
|
||||
Error,
|
||||
StandardFunction,
|
||||
Link,
|
||||
Heading,
|
||||
Literal
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
20
TightWiki.Engine.Library/HandlerResult.cs
Normal file
20
TightWiki.Engine.Library/HandlerResult.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using static TightWiki.Engine.Library.Constants;
|
||||
|
||||
namespace TightWiki.Engine.Library
|
||||
{
|
||||
public class HandlerResult
|
||||
{
|
||||
public string Content { get; set; } = string.Empty;
|
||||
|
||||
public List<HandlerResultInstruction> Instructions { get; set; } = new();
|
||||
|
||||
public HandlerResult()
|
||||
{
|
||||
}
|
||||
|
||||
public HandlerResult(string content)
|
||||
{
|
||||
Content = content;
|
||||
}
|
||||
}
|
||||
}
|
||||
15
TightWiki.Engine.Library/Interfaces/ICommentHandler.cs
Normal file
15
TightWiki.Engine.Library/Interfaces/ICommentHandler.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace TightWiki.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>
|
||||
public HandlerResult Handle(ITightEngineState state, string text);
|
||||
}
|
||||
}
|
||||
14
TightWiki.Engine.Library/Interfaces/ICompletionHandler.cs
Normal file
14
TightWiki.Engine.Library/Interfaces/ICompletionHandler.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace TightWiki.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>
|
||||
public void Complete(ITightEngineState state);
|
||||
}
|
||||
}
|
||||
16
TightWiki.Engine.Library/Interfaces/IEmojiHandler.cs
Normal file
16
TightWiki.Engine.Library/Interfaces/IEmojiHandler.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace TightWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles wiki emojis.
|
||||
/// </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>
|
||||
public HandlerResult Handle(ITightEngineState state, string key, int scale);
|
||||
}
|
||||
}
|
||||
16
TightWiki.Engine.Library/Interfaces/IExceptionHandler.cs
Normal file
16
TightWiki.Engine.Library/Interfaces/IExceptionHandler.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace TightWiki.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>
|
||||
public void Log(ITightEngineState state, Exception? ex, string customText);
|
||||
}
|
||||
}
|
||||
18
TightWiki.Engine.Library/Interfaces/IExternalLinkHandler.cs
Normal file
18
TightWiki.Engine.Library/Interfaces/IExternalLinkHandler.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace TightWiki.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>
|
||||
public HandlerResult Handle(ITightEngineState state, string link, string? text, string? image);
|
||||
}
|
||||
}
|
||||
24
TightWiki.Engine.Library/Interfaces/IFunctionHandler.cs
Normal file
24
TightWiki.Engine.Library/Interfaces/IFunctionHandler.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using TightWiki.Engine.Function;
|
||||
|
||||
namespace TightWiki.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>
|
||||
public HandlerResult Handle(ITightEngineState state, FunctionCall function, string? scopeBody = null);
|
||||
}
|
||||
}
|
||||
17
TightWiki.Engine.Library/Interfaces/IHeadingHandler.cs
Normal file
17
TightWiki.Engine.Library/Interfaces/IHeadingHandler.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace TightWiki.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>
|
||||
public HandlerResult Handle(ITightEngineState state, int depth, string link, string text);
|
||||
}
|
||||
}
|
||||
21
TightWiki.Engine.Library/Interfaces/IInternalLinkHandler.cs
Normal file
21
TightWiki.Engine.Library/Interfaces/IInternalLinkHandler.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using TightWiki.Library;
|
||||
|
||||
namespace TightWiki.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(ITightEngineState state, NamespaceNavigation pageNavigation, string pageName, string linkText, string? image, int imageScale);
|
||||
}
|
||||
}
|
||||
16
TightWiki.Engine.Library/Interfaces/IMarkupHandler.cs
Normal file
16
TightWiki.Engine.Library/Interfaces/IMarkupHandler.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace TightWiki.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>
|
||||
public HandlerResult Handle(ITightEngineState state, char sequence, string scopeBody);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace TightWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles post-processing function calls.
|
||||
/// </summary>
|
||||
public interface IPostProcessingFunctionHandler : IFunctionHandler
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace TightWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles processing-instruction function calls.
|
||||
/// </summary>
|
||||
public interface IProcessingInstructionFunctionHandler : IFunctionHandler
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace TightWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles scope function calls.
|
||||
/// </summary>
|
||||
public interface IScopeFunctionHandler : IFunctionHandler
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace TightWiki.Engine.Library.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles standard function calls.
|
||||
/// </summary>
|
||||
public interface IStandardFunctionHandler : IFunctionHandler
|
||||
{
|
||||
}
|
||||
}
|
||||
24
TightWiki.Engine.Library/Interfaces/ITightEngine.cs
Normal file
24
TightWiki.Engine.Library/Interfaces/ITightEngine.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using TightWiki.Library.Interfaces;
|
||||
using static TightWiki.Engine.Library.Constants;
|
||||
|
||||
namespace TightWiki.Engine.Library.Interfaces
|
||||
{
|
||||
|
||||
public interface ITightEngine
|
||||
{
|
||||
IScopeFunctionHandler ScopeFunctionHandler { get; }
|
||||
IStandardFunctionHandler StandardFunctionHandler { get; }
|
||||
IProcessingInstructionFunctionHandler ProcessingInstructionFunctionHandler { get; }
|
||||
IPostProcessingFunctionHandler PostProcessingFunctionHandler { get; }
|
||||
IMarkupHandler MarkupHandler { get; }
|
||||
IHeadingHandler HeadingHandler { get; }
|
||||
ICommentHandler CommentHandler { get; }
|
||||
IEmojiHandler EmojiHandler { get; }
|
||||
IExternalLinkHandler ExternalLinkHandler { get; }
|
||||
IInternalLinkHandler InternalLinkHandler { get; }
|
||||
IExceptionHandler ExceptionHandler { get; }
|
||||
ICompletionHandler CompletionHandler { get; }
|
||||
ITightEngineState Transform(ISessionState? sessionState, IPage page, int? revision = null, WikiMatchType[]? omitMatches = null);
|
||||
//ITightEngineState TransformChild(ITightEngineState parent, IPage page, int? revision = null);
|
||||
}
|
||||
}
|
||||
75
TightWiki.Engine.Library/Interfaces/ITightEngineState.cs
Normal file
75
TightWiki.Engine.Library/Interfaces/ITightEngineState.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using TightWiki.Library.Interfaces;
|
||||
using static TightWiki.Engine.Library.Constants;
|
||||
|
||||
namespace TightWiki.Engine.Library.Interfaces
|
||||
{
|
||||
public interface ITightEngineState
|
||||
{
|
||||
#region Parameters.
|
||||
|
||||
ISessionState? Session { get; }
|
||||
IQueryCollection QueryString { get; }
|
||||
|
||||
ITightEngine Engine { get; }
|
||||
IPage Page { get; }
|
||||
int? Revision { get; }
|
||||
public HashSet<WikiMatchType> OmitMatches { get; }
|
||||
public int NestDepth { get; } //Used for recursion.
|
||||
|
||||
#endregion
|
||||
|
||||
#region State.
|
||||
|
||||
/// <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; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Results.
|
||||
|
||||
string HtmlResult { get; }
|
||||
TimeSpan ProcessingTime { get; }
|
||||
int ErrorCount { get; }
|
||||
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>
|
||||
/// <returns></returns>
|
||||
ITightEngineState TransformChild(IPage page, int? revision = null);
|
||||
}
|
||||
}
|
||||
54
TightWiki.Engine.Library/PageReference.cs
Normal file
54
TightWiki.Engine.Library/PageReference.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
namespace TightWiki.Engine.Library
|
||||
{
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is PageReference other
|
||||
&& string.Equals(Navigation, other.Navigation, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Navigation.GetHashCode();
|
||||
}
|
||||
|
||||
public PageReference(string name, string navigation)
|
||||
{
|
||||
var parts = name.Split("::");
|
||||
|
||||
if (parts.Length == 1)
|
||||
{
|
||||
Name = parts[0].Trim();
|
||||
}
|
||||
else if (parts.Length == 2)
|
||||
{
|
||||
Namespace = parts[0].Trim();
|
||||
Name = parts[1].Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid page name {name}");
|
||||
}
|
||||
|
||||
Navigation = navigation;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
TightWiki.Engine.Library/TableOfContentsTag.cs
Normal file
21
TightWiki.Engine.Library/TableOfContentsTag.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace TightWiki.Engine.Library
|
||||
{
|
||||
/// <summary>
|
||||
/// Table of contents tag.
|
||||
/// </summary>
|
||||
public class TableOfContentsTag
|
||||
{
|
||||
public int Level;
|
||||
public string HrefTag;
|
||||
public string Text;
|
||||
public int StartingPosition;
|
||||
|
||||
public TableOfContentsTag(int level, int startingPosition, string hrefTag, string text)
|
||||
{
|
||||
Level = level;
|
||||
StartingPosition = startingPosition;
|
||||
HrefTag = hrefTag;
|
||||
Text = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
TightWiki.Engine.Library/TightWiki.Engine.Library.csproj
Normal file
19
TightWiki.Engine.Library/TightWiki.Engine.Library.csproj
Normal file
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>2.20.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<DebugSymbols>False</DebugSymbols>
|
||||
<DebugType>None</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TightWiki.Engine.Function\TightWiki.Engine.Function.csproj" />
|
||||
<ProjectReference Include="..\TightWiki.Library\TightWiki.Library.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user