1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

Fix color code tag helper not being loaded

This commit is contained in:
RaidMax
2019-12-07 10:49:40 -06:00
parent e6f312392a
commit bb7d209f26
12 changed files with 18 additions and 14 deletions

View File

@ -1,43 +0,0 @@
using Microsoft.AspNetCore.Razor.TagHelpers;
using SharedLibraryCore;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;
namespace WebfrontCore.TagHelpers
{
[HtmlTargetElement("color-code")]
public class ColorCode : TagHelper
{
public string Value { get; set; }
public bool Allow { get; set; } = false;
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "ColorCode";
output.TagMode = TagMode.StartTagAndEndTag;
if (Allow)
{
var matches = Regex.Matches(Value, @"\^([0-9]|\:)([^\^]*)");
foreach (Match match in matches)
{
char colorCode = match.Groups[1].ToString().Last();
output.PreContent.AppendHtml($"<span class='text-color-code-{(colorCode >= 48 && colorCode <= 57 ? colorCode.ToString() : ((int)colorCode).ToString())}'>");
output.PreContent.Append(match.Groups[2].ToString());
output.PreContent.AppendHtml("</span>");
}
if (matches.Count <= 1)
{
output.PreContent.SetContent(Value.StripColors());
}
}
else
{
output.PreContent.SetContent(Value.StripColors());
}
}
}
}

View File

@ -1,3 +1,4 @@
@using SharedLibraryCore
@using WebfrontCore
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, WebfrontCore
@addTagHelper *, SharedLibraryCore