diff --git a/website/Ignis.Website/Components/HighlightText.razor b/website/Ignis.Website/Components/HighlightText.razor index 2157425..a84add8 100644 --- a/website/Ignis.Website/Components/HighlightText.razor +++ b/website/Ignis.Website/Components/HighlightText.razor @@ -1,6 +1,10 @@ -@inherits IgnisComponentBase +@using System.Text +@using System.Text.RegularExpressions +@inherits IgnisComponentBase -@Text + + @HighlightedText + @code { @@ -9,4 +13,27 @@ [Parameter, EditorRequired] public string Query { get; set; } = null!; [Parameter] public string? HighlightClass { get; set; } + + public MarkupString HighlightedText + { + get + { + var parts = Regex.Split(Text, $"({Regex.Escape(Query)})", RegexOptions.IgnoreCase); + + var sb = new StringBuilder(); + foreach (var part in parts) + { + if (string.Equals(part, Query, StringComparison.OrdinalIgnoreCase)) + { + sb.Append($"{part}"); + } + else + { + sb.Append($"{part}"); + } + } + + return (MarkupString)sb.ToString(); + } + } } \ No newline at end of file diff --git a/website/Ignis.Website/Components/SearchDialog.razor b/website/Ignis.Website/Components/SearchDialog.razor index b84073e..bbf1d9a 100644 --- a/website/Ignis.Website/Components/SearchDialog.razor +++ b/website/Ignis.Website/Components/SearchDialog.razor @@ -4,6 +4,7 @@ @inherits IgnisAsyncComponentBase @implements IHandleAfterRender @inject ISearchService SearchService +@inject NavigationManager Router @inject IJSRuntime JSRuntime @@ -40,12 +41,13 @@