Indexnumber parsing disabled

This commit is contained in:
Simon Martens
2023-09-16 15:43:11 +02:00
parent f054c8913d
commit d86d508786
58 changed files with 447 additions and 297 deletions

View File

@@ -1,24 +1,68 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Backlink {
public string Index { get; } = "";
public string Href { get; } = "";
public string Letter { get; } = "";
public string Page { get; } = "";
public string Line { get; } = "";
public string MarginalIndex { get; } = "";
public string? Letter { get; } = "";
public string? Page { get; } = "";
public string? Line { get; } = "";
public string? Comment { get; }
public Backlink(
string index,
string letter,
string page,
string line,
string marginalindex
string href,
string? letter,
string? page,
string? line,
string? comment = null
) {
Index = index;
Href = href;
Letter = letter;
Page = page;
Line = line;
MarginalIndex = marginalindex;
Comment = comment;
}
public static Backlink? FromXElement(XElement element) {
if (!element.HasAttributes || element.Name != "link") return null;
if (element.Attribute("ref")?.Value == null && element.Attribute("subref")?.Value == null) return null;
if (element.Ancestors("marginal") == null || !element.Ancestors("marginal").Any()) {
var marginal = element.Ancestors("marginal").First();
if (Marginal.FromXElement(marginal) == null) return null;
return new Backlink(
element.Attribute("subref")?.Value ?? element.Attribute("ref")!.Value,
marginal.Attribute("letter")!.Value,
marginal.Attribute("page")!.Value,
marginal.Attribute("line")!.Value
);
}
if (element.Ancestors("subsection") != null || !element.Ancestors("subsection").Any()) {
var subsection = element.Ancestors("subsection").First();
if (subsection.Attribute("id")?.Value == null) return null;
return new Backlink(
element.Attribute("subref")?.Value ?? element.Attribute("ref")!.Value,
null,
null,
null,
subsection.Attribute("id")!.Value
);
}
if (element.Ancestors("kommentar") != null || !element.Ancestors("kommentar").Any()) {
var kommentar = element.Ancestors("kommentar").First();
if (kommentar.Attribute("id")?.Value == null) return null;
return new Backlink(
element.Attribute("subref")?.Value ?? element.Attribute("ref")!.Value,
null,
null,
null,
kommentar.Attribute("id")!.Value
);
}
return null;
}
}
}