divan/RMuseum/Utils/DivanHtmlTools.cs
Anas Rashid 532d005cdb Rename Ganjoor -> Divan throughout the code
Projects (GanjooRazor -> DivanRazor, GanjoorService.sln -> DivanService.sln), files,
folders, classes, namespaces, settings, API routes (/api/divan) and DB tables (Divan*).
External addresses (ganjoor.net, github.com/ganjoor) unchanged. Migrations renamed
consistently (no pending model changes); requires a fresh database.
Upstream RUNNING_LOCALLY/SEMANTIC_SEARCH docs archived unmodified under docs/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 23:49:01 +02:00

39 lines
1.2 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
namespace RMuseum.Utils
{
public class DivanHtmlTools
{
public static string StripHtmlTags(string input)
{
// Remove HTML tags using Regex
string textWithoutTags = Regex.Replace(input, "<.*?>", string.Empty);
// Decode HTML entities (e.g., &amp; → &)
return HttpUtility.HtmlDecode(textWithoutTags);
}
public static List<string> ExtractLinksWithRegex(string html)
{
List<string> links = new List<string>();
string pattern = @"<(a|img)\b[^>]*?\b(href|src)\s*=\s*[""']?([^""' >]+)[""']?";
MatchCollection matches = Regex.Matches(html, pattern, RegexOptions.IgnoreCase);
foreach (Match match in matches)
{
if (match.Groups.Count >= 4)
{
string url = match.Groups[3].Value;
if (!string.IsNullOrEmpty(url))
links.Add(url);
}
}
return links.Distinct().ToList(); // Remove duplicates
}
}
}