I am using RichTextbox of Radzen to add comment from UI
I want to show link as clickable
it look like this after render
I am using below function as convert this string to render ready
Actual string stored in DB and coming for render
Test comment from UI<div><span style="font-family: var(--mud-typography-body1-family); font-size: var(--mud-typography-body1-size); font-weight: var(--mud-typography-body1-weight); letter-spacing: var(--mud-typography-body1-letterspacing); text-transform: var(--mud-typography-body1-text-transform); color: var(--mud-palette-text-primary);">Adding data from UI </span><br></div><div><br>https://www.google.com/search?q=sample+link&rlz=1C1CHWA_enIN1032IN1032&sxsrf=APwXEde-ZwfaBWMiBW7hUGv8aGEEgQyi-Q:1682440201890&ei=CQBIZMn6NYqRseMP0LubEA&start=10&sa=N&ved=2ahUKEwiJo9uUusX-AhWKSGwGHdDdBgIQ8NMDegQIBhAW&biw=1745&bih=881&dpr=1.1<br><br>https://crypto.stanford.edu/cs142/lectures/url.html<br>Thank you </div>
UI code in blazor
@((MarkupString)(TicketHistory.Message.ConvertTextUrlToLink()))
extension method
public static string ConvertTextUrlToLink(this string arg)
{
string originalString = arg;
try
{
//arg.Replace("https://www")
Regex urlregex = new Regex(@"(^|[\n ])(?<url>(www|ftp)\.[^ ,""\s<]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
arg = urlregex.Replace(arg, " <a href=\"http://${url}\" target=\"_blank\"><u>${url}</u></a>");
Regex httpurlregex = new Regex(@"(^|[\n ])(?<url>(http://www\.|https://www\.|http://|https://)[^ ,""\s<]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
arg = httpurlregex.Replace(arg, " <a href=\"${url}\" target=\"_blank\"><u>${url}</u></a>");
Regex emailregex = new Regex(@"(?<url>[a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+\s)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
arg = emailregex.Replace(arg, " <a href=\"mailto:${url}\"><u>${url}</u></a> ");
if (originalString.Equals(arg, StringComparison.OrdinalIgnoreCase))
{
Regex urlRegex1 = new Regex(@"(http:\/\/([\w.]+\/?)\S*)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
arg = urlRegex1.Replace(arg,
"<a href=\"$1\" target=\"_blank\">$1</a>");
//string regex = @"((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])";
//Regex filterRegex = new Regex(regex, RegexOptions.IgnoreCase);
//arg = filterRegex.Replace(arg, "<a href=\"$1\" title=\"$1\" target=\"_blank\"><u>$1</u></a>").Replace("href=\"www", "href=\"http://www");
}
return arg;
}
catch (Exception)
{
return originalString;
}
}