Fix note bugs (#306)

This commit is contained in:
Leendert de Borst
2024-10-18 16:04:34 +02:00
parent be62fc9127
commit c969cd738f

View File

@@ -2,7 +2,9 @@
<div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">
<h3 class="mb-4 text-xl font-semibold dark:text-white">Notes</h3>
@((MarkupString)ConvertUrlsToLinks(Notes.Replace(Environment.NewLine, "<br>")))
<div class="dark:text-gray-300">
@((MarkupString)ConvertUrlsToLinks(Notes).Replace(Environment.NewLine, "<br>"))
</div>
</div>
@code {
@@ -15,6 +17,14 @@
private static string ConvertUrlsToLinks(string text)
{
string urlPattern = @"(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})";
return Regex.Replace(text, urlPattern, match => $"<a href=\"{match.Value}\" target=\"_blank\" class=\"text-blue-500 hover:underline\">{match.Value}</a>", RegexOptions.None, TimeSpan.FromMilliseconds(100));
return Regex.Replace(text, urlPattern, match =>
{
string url = match.Value;
if (!url.StartsWith("http://") && !url.StartsWith("https://"))
{
url = "http://" + url;
}
return $"<a href=\"{url}\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"text-blue-500 hover:underline\">{match.Value}</a>";
}, RegexOptions.None, TimeSpan.FromMilliseconds(200));
}
}