1
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
{
|
||||
public class WikiOrderedMatch
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public WikiOrderedMatch()
|
||||
{
|
||||
Value = string.Empty;
|
||||
|
||||
@@ -93,9 +93,10 @@ namespace ZelWiki.Engine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换单行和多行的基本标记,如粗体、斜体、下划线等.
|
||||
/// 转换单行和多行的基本标记,如粗体、斜体、下划线等
|
||||
/// </summary>
|
||||
/// <param name="pageContent"></param>
|
||||
/// <param name="matchStore"></param>
|
||||
private static void TransformMarkup(WikiString pageContent, Dictionary<string, string> matchStore)
|
||||
{
|
||||
var symbols = WikiUtility.GetApplicableSymbols(pageContent.Value);
|
||||
@@ -127,9 +128,10 @@ namespace ZelWiki.Engine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换链接,这些链接可以是内部Wiki链接或外部链接.
|
||||
/// 转换链接,这些链接可以是内部Wiki链接或外部链接
|
||||
/// </summary>
|
||||
/// <param name="pageContent"></param>
|
||||
/// <param name="matchStore"></param>
|
||||
private static void TransformLinks(WikiString pageContent, Dictionary<string, string> matchStore)
|
||||
{
|
||||
//解析外部链接 [[http://test.net]].
|
||||
@@ -137,7 +139,7 @@ namespace ZelWiki.Engine
|
||||
var matches = WikiUtility.OrderMatchesByLengthDescending(rgx.Matches(pageContent.ToString()));
|
||||
foreach (var match in matches)
|
||||
{
|
||||
string keyword = match.Value.Substring(2, match.Value.Length - 4).Trim();
|
||||
var keyword = match.Value.Substring(2, match.Value.Length - 4).Trim();
|
||||
var args = FunctionParser.ParseRawArgumentsAddParenthesis(keyword);
|
||||
|
||||
if (args.Count > 1)
|
||||
@@ -155,7 +157,7 @@ namespace ZelWiki.Engine
|
||||
matches = WikiUtility.OrderMatchesByLengthDescending(rgx.Matches(pageContent.ToString()));
|
||||
foreach (var match in matches)
|
||||
{
|
||||
string keyword = match.Value.Substring(2, match.Value.Length - 4).Trim();
|
||||
var keyword = match.Value.Substring(2, match.Value.Length - 4).Trim();
|
||||
var args = FunctionParser.ParseRawArgumentsAddParenthesis(keyword);
|
||||
|
||||
if (args.Count == 1)
|
||||
@@ -173,7 +175,7 @@ namespace ZelWiki.Engine
|
||||
matches = WikiUtility.OrderMatchesByLengthDescending(rgx.Matches(pageContent.ToString()));
|
||||
foreach (var match in matches)
|
||||
{
|
||||
string keyword = match.Value.Substring(2, match.Value.Length - 4);
|
||||
var keyword = match.Value.Substring(2, match.Value.Length - 4);
|
||||
var args = FunctionParser.ParseRawArgumentsAddParenthesis(keyword);
|
||||
|
||||
if (args.Count == 1)
|
||||
|
||||
@@ -50,14 +50,15 @@ namespace ZelWiki.Engine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换给定页面的内容.
|
||||
/// 转换给定页面的内容
|
||||
/// </summary>
|
||||
/// <param name="session">The users current state, used for localization.</param>
|
||||
/// <param name="page">The page that is being processed.</param>
|
||||
/// <param name="revision">The revision of the page that is being processed.</param>
|
||||
/// <param name="omitMatches">The type of matches that we want to omit from processing.</param>
|
||||
/// <param name="session"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="revision"></param>
|
||||
/// <param name="omitMatches"></param>
|
||||
/// <returns></returns>
|
||||
public IZelEngineState Transform(ISessionState? session, IPage page, int? revision = null, Constants.WikiMatchType[]? omitMatches = null)
|
||||
public IZelEngineState Transform(ISessionState? session, IPage page, int? revision = null,
|
||||
Constants.WikiMatchType[]? omitMatches = null)
|
||||
=> new ZelEngineState(this, session, page, revision, omitMatches).Transform();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace ZelWiki.Engine
|
||||
private readonly string _tocName = "TOC_" + new Random().Next(0, 1000000).ToString();
|
||||
private readonly Dictionary<string, object> _handlerState = new();
|
||||
|
||||
#region 公共属性.
|
||||
#region 公共属性
|
||||
|
||||
/// <summary>
|
||||
/// 通过调用设置自定义页面标题 @@Title("...")
|
||||
@@ -46,13 +46,13 @@ namespace ZelWiki.Engine
|
||||
|
||||
#endregion
|
||||
|
||||
#region 入参.
|
||||
#region 入参
|
||||
|
||||
public IPage Page { get; }
|
||||
public int? Revision { get; }
|
||||
public IQueryCollection QueryString { get; }
|
||||
public ISessionState? Session { get; }
|
||||
public HashSet<Constants.WikiMatchType> OmitMatches { get; private set; } = new();
|
||||
public HashSet<WikiMatchType> OmitMatches { get; private set; } = new();
|
||||
public int NestDepth { get; private set; } //用于递归
|
||||
|
||||
#endregion
|
||||
@@ -258,7 +258,7 @@ namespace ZelWiki.Engine
|
||||
var orderedMatches = WikiUtility.OrderMatchesByLengthDescending(rgx.Matches(pageContent.ToString()));
|
||||
foreach (var match in orderedMatches)
|
||||
{
|
||||
string body = match.Value.Substring(sequence.Length, match.Value.Length - sequence.Length * 2);
|
||||
var body = match.Value.Substring(sequence.Length, match.Value.Length - sequence.Length * 2);
|
||||
|
||||
var result = Engine.MarkupHandler.Handle(this, symbol, body);
|
||||
|
||||
@@ -273,7 +273,7 @@ namespace ZelWiki.Engine
|
||||
foreach (var match in sizeUpOrderedMatches)
|
||||
{
|
||||
var headingMarkers = 0;
|
||||
foreach (char c in match.Value)
|
||||
foreach (var c in match.Value)
|
||||
{
|
||||
if (c != '^')
|
||||
{
|
||||
@@ -285,9 +285,9 @@ namespace ZelWiki.Engine
|
||||
|
||||
if (headingMarkers >= 2 && headingMarkers <= 6)
|
||||
{
|
||||
string value = match.Value.Substring(headingMarkers, match.Value.Length - headingMarkers).Trim();
|
||||
var value = match.Value.Substring(headingMarkers, match.Value.Length - headingMarkers).Trim();
|
||||
|
||||
int fontSize = 1 + headingMarkers;
|
||||
var fontSize = 1 + headingMarkers;
|
||||
if (fontSize < 1) fontSize = 1;
|
||||
|
||||
var markup = "<font size=\"" + fontSize + "\">" + value + "</font>\r\n";
|
||||
@@ -332,11 +332,9 @@ namespace ZelWiki.Engine
|
||||
{
|
||||
startPos = content.LastIndexOf("{{", startPos);
|
||||
if (startPos < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
int endPos = content.IndexOf("}}", startPos);
|
||||
|
||||
var endPos = content.IndexOf("}}", startPos);
|
||||
|
||||
if (endPos < 0 || endPos < startPos)
|
||||
{
|
||||
@@ -383,11 +381,11 @@ namespace ZelWiki.Engine
|
||||
|
||||
foreach (var match in orderedMatches)
|
||||
{
|
||||
int paramEndIndex = -1;
|
||||
var paramEndIndex = -1;
|
||||
|
||||
FunctionCall function;
|
||||
|
||||
string mockFunctionCall = "##" + match.Value.Trim([' ', '\t', '{', '}']);
|
||||
var mockFunctionCall = "##" + match.Value.Trim([' ', '\t', '{', '}']);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -406,7 +404,7 @@ namespace ZelWiki.Engine
|
||||
continue;
|
||||
}
|
||||
|
||||
string scopeBody = mockFunctionCall.Substring(paramEndIndex).Trim();
|
||||
var scopeBody = mockFunctionCall.Substring(paramEndIndex).Trim();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -544,7 +542,7 @@ namespace ZelWiki.Engine
|
||||
/// <param name="pageContent"></param>
|
||||
private void TransformLinks(WikiString pageContent)
|
||||
{
|
||||
//Parse external explicit links. eg. [[http://test.net]].
|
||||
//外链 [[http://test.net]].
|
||||
var orderedMatches = WikiUtility.OrderMatchesByLengthDescending(
|
||||
PrecompiledRegex.TransformExplicitHTTPLinks().Matches(pageContent.ToString()));
|
||||
|
||||
@@ -568,12 +566,12 @@ namespace ZelWiki.Engine
|
||||
}
|
||||
|
||||
var result = Engine.ExternalLinkHandler.Handle(this, link, text, image);
|
||||
StoreHandlerResult(result, Constants.WikiMatchType.Link, pageContent, match.Value, string.Empty);
|
||||
StoreHandlerResult(result, WikiMatchType.Link, pageContent, match.Value, string.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = Engine.ExternalLinkHandler.Handle(this, link, link, null);
|
||||
StoreHandlerResult(result, Constants.WikiMatchType.Link, pageContent, match.Value, string.Empty);
|
||||
StoreHandlerResult(result, WikiMatchType.Link, pageContent, match.Value, string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -582,15 +580,15 @@ namespace ZelWiki.Engine
|
||||
|
||||
foreach (var match in orderedMatches)
|
||||
{
|
||||
string link = match.Value.Substring(2, match.Value.Length - 4).Trim();
|
||||
var link = match.Value.Substring(2, match.Value.Length - 4).Trim();
|
||||
var args = FunctionParser.ParseRawArgumentsAddParenthesis(link);
|
||||
|
||||
if (args.Count > 1)
|
||||
{
|
||||
link = args[0];
|
||||
string? text = args[1];
|
||||
var text = args[1];
|
||||
|
||||
string imageTag = "image:";
|
||||
var imageTag = "image:";
|
||||
string? image = null;
|
||||
|
||||
if (text.StartsWith(imageTag, StringComparison.CurrentCultureIgnoreCase))
|
||||
@@ -600,12 +598,12 @@ namespace ZelWiki.Engine
|
||||
}
|
||||
|
||||
var result = Engine.ExternalLinkHandler.Handle(this, link, text, image);
|
||||
StoreHandlerResult(result, Constants.WikiMatchType.Link, pageContent, match.Value, string.Empty);
|
||||
StoreHandlerResult(result, WikiMatchType.Link, pageContent, match.Value, string.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = Engine.ExternalLinkHandler.Handle(this, link, link, null);
|
||||
StoreHandlerResult(result, Constants.WikiMatchType.Link, pageContent, match.Value, string.Empty);
|
||||
StoreHandlerResult(result, WikiMatchType.Link, pageContent, match.Value, string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -614,14 +612,14 @@ namespace ZelWiki.Engine
|
||||
|
||||
foreach (var match in orderedMatches)
|
||||
{
|
||||
string keyword = match.Value.Substring(2, match.Value.Length - 4);
|
||||
var keyword = match.Value.Substring(2, match.Value.Length - 4);
|
||||
|
||||
var args = FunctionParser.ParseRawArgumentsAddParenthesis(keyword);
|
||||
|
||||
string pageName;
|
||||
string text;
|
||||
string? image = null;
|
||||
int imageScale = 100;
|
||||
var imageScale = 100;
|
||||
|
||||
if (args.Count == 1)
|
||||
{
|
||||
@@ -632,7 +630,7 @@ namespace ZelWiki.Engine
|
||||
{
|
||||
pageName = args[0];
|
||||
|
||||
string imageTag = "image:";
|
||||
var imageTag = "image:";
|
||||
if (args[1].StartsWith(imageTag, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
image = args[1].Substring(imageTag.Length).Trim();
|
||||
@@ -694,7 +692,7 @@ namespace ZelWiki.Engine
|
||||
try
|
||||
{
|
||||
function = FunctionParser.ParseAndGetFunctionCall(functionHandler.Prototypes, match.Value,
|
||||
out int matchEndIndex);
|
||||
out var matchEndIndex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -722,7 +720,6 @@ namespace ZelWiki.Engine
|
||||
/// <param name="isFirstChance"></param>
|
||||
private void TransformStandardFunctions(WikiString pageContent, bool isFirstChance)
|
||||
{
|
||||
//Remove the last "(\#\#[\w-]+)" if you start to have matching problems:
|
||||
var orderedMatches = WikiUtility.OrderMatchesByLengthDescending(
|
||||
PrecompiledRegex.TransformFunctions().Matches(pageContent.ToString()));
|
||||
|
||||
@@ -745,9 +742,8 @@ namespace ZelWiki.Engine
|
||||
if (parsed != default)
|
||||
{
|
||||
if (postProcessPrototypes.Exists(parsed.Prefix, parsed.Name))
|
||||
{
|
||||
continue; //This IS a function, but it is meant to be parsed at the end of processing.
|
||||
}
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
StoreError(pageContent, match.Value, ex.Message);
|
||||
@@ -759,7 +755,7 @@ namespace ZelWiki.Engine
|
||||
continue;
|
||||
}
|
||||
|
||||
var firstChanceFunctions = new string[] { "include", "inject" }; //Process these the first time through.
|
||||
var firstChanceFunctions = new string[] { "include", "inject" };
|
||||
if (isFirstChance && firstChanceFunctions.Contains(function.Name.ToLower()) == false)
|
||||
{
|
||||
continue;
|
||||
@@ -768,7 +764,7 @@ namespace ZelWiki.Engine
|
||||
try
|
||||
{
|
||||
var result = functionHandler.Handle(this, function, string.Empty);
|
||||
StoreHandlerResult(result, Constants.WikiMatchType.StandardFunction, pageContent, match.Value,
|
||||
StoreHandlerResult(result, WikiMatchType.StandardFunction, pageContent, match.Value,
|
||||
string.Empty);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -784,7 +780,6 @@ namespace ZelWiki.Engine
|
||||
/// <param name="pageContent"></param>
|
||||
private void TransformPostProcessingFunctions(WikiString pageContent)
|
||||
{
|
||||
//Remove the last "(\#\#[\w-]+)" if you start to have matching problems:
|
||||
var orderedMatches = WikiUtility.OrderMatchesByLengthDescending(
|
||||
PrecompiledRegex.TransformPostProcess().Matches(pageContent.ToString()));
|
||||
|
||||
@@ -797,7 +792,7 @@ namespace ZelWiki.Engine
|
||||
try
|
||||
{
|
||||
function = FunctionParser.ParseAndGetFunctionCall(functionHandler.Prototypes, match.Value,
|
||||
out int matchEndIndex);
|
||||
out var matchEndIndex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -808,7 +803,7 @@ namespace ZelWiki.Engine
|
||||
try
|
||||
{
|
||||
var result = functionHandler.Handle(this, function, string.Empty);
|
||||
StoreHandlerResult(result, Constants.WikiMatchType.StandardFunction, pageContent, match.Value,
|
||||
StoreHandlerResult(result, WikiMatchType.StandardFunction, pageContent, match.Value,
|
||||
string.Empty);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -820,7 +815,7 @@ namespace ZelWiki.Engine
|
||||
|
||||
private static void TransformWhitespace(WikiString pageContent)
|
||||
{
|
||||
string identifier = $"<!--{Guid.NewGuid()}-->";
|
||||
var identifier = $"<!--{Guid.NewGuid()}-->";
|
||||
|
||||
pageContent.Replace("\r\n", "\n");
|
||||
|
||||
@@ -841,7 +836,7 @@ namespace ZelWiki.Engine
|
||||
return;
|
||||
}
|
||||
|
||||
bool allowNestedDecode =
|
||||
var allowNestedDecode =
|
||||
!result.Instructions.Contains(HandlerResultInstruction.DisallowNestedProcessing);
|
||||
|
||||
string identifier;
|
||||
@@ -881,7 +876,7 @@ namespace ZelWiki.Engine
|
||||
ErrorCount++;
|
||||
_matchesStoredPerIteration++;
|
||||
|
||||
string identifier = $"<!--{Guid.NewGuid()}-->";
|
||||
var identifier = $"<!--{Guid.NewGuid()}-->";
|
||||
|
||||
var matchSet = new WikiMatchSet()
|
||||
{
|
||||
@@ -902,7 +897,7 @@ namespace ZelWiki.Engine
|
||||
MatchCount++;
|
||||
_matchesStoredPerIteration++;
|
||||
|
||||
string identifier = $"<!--{Guid.NewGuid()}-->";
|
||||
var identifier = $"<!--{Guid.NewGuid()}-->";
|
||||
|
||||
var matchSet = new WikiMatchSet()
|
||||
{
|
||||
@@ -923,7 +918,7 @@ namespace ZelWiki.Engine
|
||||
MatchCount++;
|
||||
_matchesStoredPerIteration++;
|
||||
|
||||
string identifier = $"<!--{Guid.NewGuid()}-->";
|
||||
var identifier = $"<!--{Guid.NewGuid()}-->";
|
||||
|
||||
var matchSet = new WikiMatchSet()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user