divan/RMuseum/Utils/DivanPoemTools.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

43 lines
1.3 KiB
C#

namespace RMuseum.Utils
{
/// <summary>
/// divan poem tools
/// </summary>
public static class DivanPoemTools
{
/// <summary>
/// get an excerpt for the poem
/// </summary>
/// <param name="poemHtml"></param>
/// <returns></returns>
public static string GetPoemHtmlExcerpt(string poemHtml)
{
while (poemHtml.IndexOf("id=\"bn") != -1)
{
int idxbn1 = poemHtml.IndexOf(" id=\"bn");
int idxbn2 = poemHtml.IndexOf("\"", idxbn1 + " id=\"bn".Length);
poemHtml = poemHtml.Substring(0, idxbn1) + poemHtml.Substring(idxbn2 + 1);
}
poemHtml = poemHtml.Replace("<div class=\"b\">", "").Replace("<div class=\"b2\">", "").Replace("<div class=\"m1\">", "").Replace("<div class=\"m2\">", "").Replace("</div>", "");
int index = poemHtml.IndexOf("<p>");
int count = 0;
while (index != -1 && count < 5)
{
index = poemHtml.IndexOf("<p>", index + 1);
count++;
}
if (index != -1)
{
poemHtml = poemHtml.Substring(0, index);
poemHtml += "<p>[...]</p>";
}
return poemHtml;
}
}
}