mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 01:05:32 +00:00
Bugfix: doppelte Marginalien
This commit is contained in:
42
HaWeb/Settings/NodeRules/MarginalCollection.cs
Normal file
42
HaWeb/Settings/NodeRules/MarginalCollection.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using HaWeb.Models;
|
||||
using System.Xml.Linq;
|
||||
using HaWeb.XMLTests;
|
||||
namespace HaWeb.Settings.NodeRules;
|
||||
|
||||
public class MarginalCollectionRules : ICollectionRule {
|
||||
public string Name { get; } = "marginal";
|
||||
public HamannXPath[] Bases { get; } = {
|
||||
new HamannXPath() { Documents = new[] { "stellenkommentar" }, XPath = "//marginal"}
|
||||
};
|
||||
public HamannXPath[] Backlinks { get; } = {};
|
||||
|
||||
public IEnumerable<(string, XElement, XMLRootDocument)> GenerateIdentificationStrings(IEnumerable<(XElement, XMLRootDocument)> list) {
|
||||
foreach (var e in list) {
|
||||
var id = e.Item1.Attribute("letter")!.Value;
|
||||
id += "-";
|
||||
id += e.Item1.Attribute("page")!.Value;
|
||||
id += "-";
|
||||
id += e.Item1.Attribute("line")!.Value;
|
||||
if (e.Item1.HasAttributes && e.Item1.Attribute("sort") != null) {
|
||||
id += "-";
|
||||
id += e.Item1.Attribute("sort")!.Value;
|
||||
}
|
||||
yield return (
|
||||
id,
|
||||
e.Item1,
|
||||
e.Item2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<(string, XElement, XMLRootDocument, bool)> GenerateBacklinkString(IEnumerable<(XElement, XMLRootDocument)> list) => null;
|
||||
|
||||
|
||||
public bool CheckDatatypes(XElement element) {
|
||||
if (element.HasAttributes && element.Attribute("sort") != null ) {
|
||||
return Int32.TryParse(element.Attribute("sort").Value, out var _);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,4 +44,8 @@ public class StructureCollection : ICollectionRule {
|
||||
partialmatch);
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckDatatypes(XElement element) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,8 +234,9 @@ public class TextRules {
|
||||
if(reader.State.ParsedMarginals == null) reader.State.ParsedMarginals = new List<(string, string, string)>();
|
||||
var sb2 = new StringBuilder();
|
||||
|
||||
// Sortiert an dieser String, nicht nach Zahl: sort 1-9 ist möglich, es gibt keine Abstürze bei fehlerhaften Werten
|
||||
if (margs.Count() > 1) margs = margs.OrderBy(x => x.Sort ?? " ");
|
||||
// Sortiert an dieser Stelle nach marginal.Sort, dessen Angabe eine Zahl sein muss.
|
||||
// Der Syntaxchecker muss also überprüfen, ob doppelte Angaben gemacht sind oder Sort fehlt.
|
||||
if (margs.Count() > 1) margs = margs.Where(x => Int32.TryParse(x.Sort, out var y)).OrderBy(x => Int32.Parse(x.Sort));
|
||||
sb.Append(HaWeb.HTMLHelpers.TagHelpers.CreateElement(DEFAULTELEMENT, CSSClasses.COMMENTMARKERCLASS, "ma-" + reader.State.currpage + "-" + reader.State.currline));
|
||||
sb.Append(HaWeb.HTMLHelpers.TagHelpers.CreateEndElement(DEFAULTELEMENT));
|
||||
sb.Append(HaWeb.HTMLHelpers.TagHelpers.CreateElement(DEFAULTELEMENT, CSSClasses.MARGINGALBOXCLASS));
|
||||
|
||||
@@ -8,4 +8,5 @@ public interface ICollectionRule {
|
||||
public HamannXPath[] Backlinks { get; }
|
||||
public IEnumerable<(string, XElement, XMLRootDocument)> GenerateIdentificationStrings(IEnumerable<(XElement, XMLRootDocument)> List);
|
||||
public IEnumerable<(string, XElement, XMLRootDocument, bool)> GenerateBacklinkString(IEnumerable<(XElement, XMLRootDocument)> List);
|
||||
public bool CheckDatatypes(XElement element);
|
||||
}
|
||||
@@ -135,9 +135,12 @@ public class XMLTester {
|
||||
foreach (var r in rule.GenerateIdentificationStrings(elemens)) {
|
||||
if (!hs.Add(r.Item1)) {
|
||||
var lc = getLineColumn(r.Item2);
|
||||
_Results[r.Item3.File.FileName].Log(lc.Item1, lc.Item2, "Brief-Seite-Zeile " + r.Item1 + " mehrdeutig.");
|
||||
_Results[r.Item3.File.FileName].Log(lc.Item1, lc.Item2, "Identifikator (Brief-Seite-Zeile(-Sort))" + r.Item1 + " mehrdeutig.");
|
||||
}
|
||||
}
|
||||
foreach (var e in elemens) {
|
||||
rule.CheckDatatypes(e.Item1);
|
||||
}
|
||||
}
|
||||
}
|
||||
_CollectionIDs!.TryAdd(rule.Name, hs);
|
||||
|
||||
Reference in New Issue
Block a user