mirror of
				https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
				synced 2025-10-29 17:25:32 +00:00 
			
		
		
		
	New Font, Refactor of Layout, Expanded <link> Tags on search
This commit is contained in:
		| @@ -1,6 +1,9 @@ | ||||
| namespace HaWeb.SearchHelpers; | ||||
| using System.Text; | ||||
| using System.Web; | ||||
| using HaDocument.Models; | ||||
| using HaDocument.Interfaces; | ||||
| using System.Xml.Linq; | ||||
|  | ||||
| using TagFuncList = List<(Func<HaXMLReader.EvArgs.Tag, HaWeb.HTMLParser.LineXMLHelper<SearchState>, bool>, Action<System.Text.StringBuilder, HaXMLReader.EvArgs.Tag, HaWeb.HTMLParser.LineXMLHelper<SearchState>>)>; | ||||
| using TextFuncList = List<(Func<HaXMLReader.EvArgs.Text, HaWeb.HTMLParser.LineXMLHelper<SearchState>, bool>, Action<System.Text.StringBuilder, HaXMLReader.EvArgs.Text, HaWeb.HTMLParser.LineXMLHelper<SearchState>>)>; | ||||
| @@ -10,6 +13,42 @@ using WhitespaceFuncList = List<(Func<HaXMLReader.EvArgs.Whitespace, HaWeb.HTMLP | ||||
| public class SearchRules { | ||||
|     public static readonly TagFuncList OTagRules = new TagFuncList() { | ||||
|         ( (x, _) => x.Name.ToLower() == "kommentar" || x.Name.ToLower() == "subsection", (_, tag, reader) => reader.State.CurrentIdentifier = tag["id"]), | ||||
|         ( (x, reader) => (x.Name.ToLower() == "link" && reader.State.Lib != null), (sb, tag, reader) => { | ||||
|             // LINKTEXT NEVER GETS TO TRUE | ||||
|             Comment? comment = null; | ||||
|             if (tag.Values.ContainsKey("subref") && reader.State.Lib.SubCommentsByID.ContainsKey(tag["subref"])) | ||||
|                 comment = reader.State.Lib.SubCommentsByID[tag["subref"]]; | ||||
|             else if (tag.Values.ContainsKey("ref")) | ||||
|                 if (reader.State.Lib.Comments.ContainsKey(tag["ref"])) | ||||
|                     comment = reader.State.Lib.Comments[tag["ref"]]; | ||||
|                 else if (reader.State.Lib.SubCommentsByID.ContainsKey(tag["ref"])) | ||||
|                     comment = reader.State.Lib.SubCommentsByID[tag["ref"]]; | ||||
|             if (comment != null) { | ||||
|                 var t = String.Empty; | ||||
|                 var sw = reader.State.SearchWord; | ||||
|                 if (!String.IsNullOrWhiteSpace(comment.Lemma)) | ||||
|                     t = XElement.Parse(comment.Lemma).Value; | ||||
|                 if (reader.State.Normalize) | ||||
|                     t = HaWeb.SearchHelpers.StringHelpers.NormalizeWhiteSpace(t); | ||||
|                 if (tag["linktext"] != "false") { | ||||
|                     sb.Append(t.ToUpperInvariant()); | ||||
|                     if (sb.Length >= sw.Length) { | ||||
|                         if (sb.ToString().Contains(sw)) { | ||||
|                             if (reader.State.Results == null) | ||||
|                                 reader.State.Results = new List<(string Page, string Line, string Identifier)>(); | ||||
|                             reader.State.Results.Add((reader.CurrentPage, reader.CurrentLine, reader.State.CurrentIdentifier)); | ||||
|                         } | ||||
|                         sb.Remove(0, sb.Length - sw.Length); | ||||
|                     } | ||||
|                 } else { | ||||
|                     if (t.ToUpperInvariant().Contains(sw)) { | ||||
|                         if (reader.State.Results == null) | ||||
|                                 reader.State.Results = new List<(string Page, string Line, string Identifier)>(); | ||||
|                         reader.State.Results.Add((reader.CurrentPage, reader.CurrentLine, reader.State.CurrentIdentifier)); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         }) | ||||
|     }; | ||||
|  | ||||
|     public static readonly TextFuncList TextRules = new TextFuncList() { | ||||
| @@ -17,10 +56,10 @@ public class SearchRules { | ||||
|             var t = text.Value; | ||||
|             if (reader.State.Normalize) | ||||
|                 t = HaWeb.SearchHelpers.StringHelpers.NormalizeWhiteSpace(t); | ||||
|             sb.Append(t); | ||||
|             sb.Append(t.ToUpperInvariant()); | ||||
|             var sw = reader.State.SearchWord; | ||||
|             if (sb.Length >= sw.Length) { | ||||
|                 if (sb.ToString().ToUpperInvariant().Contains(sw)) { | ||||
|                 if (sb.ToString().Contains(sw)) { | ||||
|                     if (reader.State.Results == null) | ||||
|                         reader.State.Results = new List<(string Page, string Line, string Identifier)>(); | ||||
|                     reader.State.Results.Add((reader.CurrentPage, reader.CurrentLine, reader.State.CurrentIdentifier)); | ||||
|   | ||||
| @@ -1,13 +1,16 @@ | ||||
| namespace HaWeb.SearchHelpers; | ||||
| using System.Text; | ||||
| using HaDocument.Interfaces; | ||||
|  | ||||
| public class SearchState : HaWeb.HTMLParser.IState { | ||||
|     internal string SearchWord; | ||||
|     internal string? CurrentIdentifier; | ||||
|     internal ILibrary? Lib; | ||||
|     internal bool Normalize; | ||||
|     internal List<(string Page, string Line, string Identifier)>? Results; | ||||
|  | ||||
|     public SearchState(string searchword, bool normalize = false) { | ||||
|     public SearchState(string searchword, bool normalize = false, ILibrary? lib = null) { | ||||
|         Lib = lib; | ||||
|         Normalize = normalize; | ||||
|         SearchWord = searchword; | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Simon Martens
					Simon Martens