Skip to content

Commit

Permalink
#749 [HxMessenger] AddInformation, AddError and AddWarning extension …
Browse files Browse the repository at this point in the history
…methods should preserve line endings in text
  • Loading branch information
hakenr committed Feb 5, 2024
1 parent 26fe381 commit e8182c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions BlazorAppTest/Pages/HxMessengerTest.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/HxMessengerTest"

@* <HxMessenger /> iteself is in MainLayout.razor *@
@* <HxMessenger /> itself is in MainLayout.razor *@

<h1>HxMessenger</h1>

Expand All @@ -26,7 +26,7 @@

private void HandleAddInformationButtonClick()
{
Messenger.AddInformation("Information", "Information button clicked.");
Messenger.AddInformation("Information\nmultiline", "Information button clicked.\n<b>1</b>\n2");
}

private void HandleAddWarningButtonClick()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Havit.Blazor.Components.Web.Bootstrap;
using System.Net;

namespace Havit.Blazor.Components.Web.Bootstrap;

/// <summary>
/// Extension methods for <see cref="IHxMessengerService"/>.
Expand Down Expand Up @@ -88,11 +90,16 @@ private static RenderFragment BuildContentTemplate(string title, string text)
{
builder.OpenElement(1, "div");
builder.AddAttribute(2, "class", "fw-bold");
builder.AddContent(3, title);
builder.AddContent(3, ProcessLineEndings(title));
builder.CloseElement();
}

builder.AddContent(10, text);
builder.AddContent(10, ProcessLineEndings(text));
};
}

private static MarkupString ProcessLineEndings(string text)
{
return new MarkupString(WebUtility.HtmlEncode(text)?.ReplaceLineEndings("<br />"));
}
}

0 comments on commit e8182c0

Please sign in to comment.