NewLinesToParagraphs string extension method
This commit is contained in:
@@ -18,7 +18,7 @@ public static class CharExtensions
|
||||
{ 'ö', new char[2] { 'o', 'e' } },
|
||||
{ 'ü', new char[2] { 'u', 'e' } },
|
||||
{ 'ß', new char[2] { 's', 's' } },
|
||||
{ '&', new char[1] { '+' } }
|
||||
//{ '&', new char[1] { '+' } }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -212,8 +212,28 @@ public static class StringExtensions
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static string NewLinesToParagraphs(this string source, string classes = null)
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
string classAttribute = classes.HasValue() ? $" class=\"{classes}\"" : string.Empty;
|
||||
builder.Append($"<p{classAttribute}>");
|
||||
string[] lines = source.Split('\n');
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
builder.Append($"</p><p{classAttribute}>");
|
||||
}
|
||||
builder.Append(WebUtility.HtmlEncode(lines[i]));
|
||||
}
|
||||
|
||||
builder.Append("</p>");
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
|
||||
public static string FormatTwoFactorAuthenticationKey(this string unformattedKey)
|
||||
{
|
||||
var result = new StringBuilder();
|
||||
|
||||
Reference in New Issue
Block a user