Files
ZelWiki/ZelWiki.Engine.Implementation/ExternalLinkHandler.cs
2025-02-20 15:20:28 +08:00

38 lines
1.4 KiB
C#

using ZelWiki.Engine.Library;
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>
public HandlerResult Handle(IZelEngineState state, string link, string? text, string? image)
{
if (string.IsNullOrEmpty(image))
{
return new HandlerResult($"<a href=\"{link}\">{text}</a>")
{
Instructions = [Constants.HandlerResultInstruction.DisallowNestedProcessing]
};
}
else
{
return new HandlerResult($"<a href=\"{link}\"><img src=\"{image}\" border =\"0\"></a>")
{
Instructions = [Constants.HandlerResultInstruction.DisallowNestedProcessing]
};
}
}
}
}