mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-12-16 06:25:31 +00:00
Formatted everything; completed upload capabilities
This commit is contained in:
@@ -7,16 +7,14 @@ using HaWeb.Settings.ParsingRules;
|
||||
using HaWeb.Settings.ParsingState;
|
||||
using System.Text;
|
||||
|
||||
public static class CommentHelpers
|
||||
{
|
||||
public static class CommentHelpers {
|
||||
private static readonly string DEFAULTELEMENT = HaWeb.Settings.HTML.DEFAULTELEMENT;
|
||||
private static readonly string BACKLINKSCLASS = HaWeb.Settings.CSSClasses.BACKLINKSCLASS;
|
||||
private static readonly string LETLINKCLASS = HaWeb.Settings.CSSClasses.LETLINKCLASS;
|
||||
private static readonly string COMMENTHEADCLASS = HaWeb.Settings.CSSClasses.COMMENTHEADCLASS;
|
||||
private static readonly string BACKLINKSHKBCLASS = HaWeb.Settings.CSSClasses.BACKLINKSHKBCLASS;
|
||||
|
||||
public static string CreateHTML(ILibrary lib, IReaderService readerService, Comment comment, string category, CommentType type)
|
||||
{
|
||||
public static string CreateHTML(ILibrary lib, IReaderService readerService, Comment comment, string category, CommentType type) {
|
||||
var sb = new StringBuilder();
|
||||
var rd = readerService.RequestStringReader(comment.Lemma);
|
||||
var commentState = new CommentState(category, type);
|
||||
@@ -28,17 +26,13 @@ public static class CommentHelpers
|
||||
.Where(x => lib.Metas.ContainsKey(x.Letter))
|
||||
.OrderBy(x => lib.Metas[x.Letter].Sort)
|
||||
.ThenBy(x => lib.Metas[x.Letter].Order) : null;
|
||||
if (backlinks != null)
|
||||
{
|
||||
if (backlinks != null) {
|
||||
sb.Append(HTMLHelpers.TagHelpers.CreateElement(DEFAULTELEMENT, BACKLINKSCLASS));
|
||||
var arrow = false;
|
||||
foreach (var blk in backlinks)
|
||||
{
|
||||
foreach (var blk in backlinks) {
|
||||
var let = lib.Metas.ContainsKey(blk.Letter) ? lib.Metas[blk.Letter] : null;
|
||||
if (let != null)
|
||||
{
|
||||
if (!arrow)
|
||||
{
|
||||
if (let != null) {
|
||||
if (!arrow) {
|
||||
sb.Append(HTMLHelpers.TagHelpers.CreateElement(DEFAULTELEMENT, BACKLINKSHKBCLASS));
|
||||
sb.Append("HKB ");
|
||||
sb.Append(HTMLHelpers.TagHelpers.CreateEndElement(DEFAULTELEMENT));
|
||||
|
||||
@@ -14,36 +14,27 @@ public static class ConversionHelpers {
|
||||
{'M', 1000}
|
||||
};
|
||||
|
||||
public static int RomanToInteger(string roman)
|
||||
{
|
||||
public static int RomanToInteger(string roman) {
|
||||
var ro = roman.ToUpper();
|
||||
int number = 0;
|
||||
for (int i = 0; i < roman.Length; i++)
|
||||
{
|
||||
if (RomanMap.ContainsKey(ro[i]) && (i + 1 >= ro.Length || RomanMap.ContainsKey(ro[i + 1])))
|
||||
{
|
||||
if (i + 1 < ro.Length && RomanMap[ro[i]] < RomanMap[ro[i + 1]])
|
||||
{
|
||||
for (int i = 0; i < roman.Length; i++) {
|
||||
if (RomanMap.ContainsKey(ro[i]) && (i + 1 >= ro.Length || RomanMap.ContainsKey(ro[i + 1]))) {
|
||||
if (i + 1 < ro.Length && RomanMap[ro[i]] < RomanMap[ro[i + 1]]) {
|
||||
number -= RomanMap[ro[i]];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
number += RomanMap[ro[i]];
|
||||
}
|
||||
}
|
||||
else return 0;
|
||||
} else return 0;
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
public static int RomanOrNumberToInt(string number)
|
||||
{
|
||||
public static int RomanOrNumberToInt(string number) {
|
||||
var a = 0;
|
||||
if (Int32.TryParse(number, out a)) return a;
|
||||
else return RomanToInteger(number);
|
||||
}
|
||||
public static string ToRoman(int number)
|
||||
{
|
||||
public static string ToRoman(int number) {
|
||||
if ((number < 0) || (number > 3999)) return string.Empty;
|
||||
if (number < 1) return string.Empty;
|
||||
if (number >= 1000) return "M" + ToRoman(number - 1000);
|
||||
|
||||
@@ -11,10 +11,8 @@ using System.Xml.Linq;
|
||||
using HaWeb.Settings.ParsingState;
|
||||
using HaWeb.Settings.ParsingRules;
|
||||
|
||||
public static class LetterHelpers
|
||||
{
|
||||
public static LetterState CreateLetter(ILibrary lib, IReaderService readerService, Meta meta, Letter letter, IEnumerable<Marginal>? marginals, IEnumerable<Hand>? hands, IEnumerable<Editreason>? edits)
|
||||
{
|
||||
public static class LetterHelpers {
|
||||
public static LetterState CreateLetter(ILibrary lib, IReaderService readerService, Meta meta, Letter letter, IEnumerable<Marginal>? marginals, IEnumerable<Hand>? hands, IEnumerable<Editreason>? edits) {
|
||||
var rd = readerService.RequestStringReader(letter.Element);
|
||||
var letterState = new LetterState(lib, readerService, meta, marginals, hands, edits);
|
||||
new HaWeb.HTMLParser.XMLHelper<LetterState>(letterState, rd, letterState.sb_lettertext, LetterRules.OTagRules, LetterRules.STagRules, LetterRules.CTagRules, LetterRules.TextRules, LetterRules.WhitespaceRules);
|
||||
@@ -23,8 +21,7 @@ public static class LetterHelpers
|
||||
return letterState;
|
||||
}
|
||||
|
||||
public static TraditionState CreateTraditions(ILibrary lib, IReaderService readerService, IEnumerable<Marginal>? marginals, Tradition tradition, IEnumerable<Hand>? hands, IEnumerable<Editreason>? edits)
|
||||
{
|
||||
public static TraditionState CreateTraditions(ILibrary lib, IReaderService readerService, IEnumerable<Marginal>? marginals, Tradition tradition, IEnumerable<Hand>? hands, IEnumerable<Editreason>? edits) {
|
||||
var rd = readerService.RequestStringReader(tradition.Element);
|
||||
var traditionState = new TraditionState(lib, rd, readerService, marginals, hands, edits);
|
||||
new HaWeb.HTMLParser.XMLHelper<TraditionState>(traditionState, rd, traditionState.sb_tradition, TraditionRules.OTagRules, TraditionRules.STagRules, TraditionRules.CTagRules, TraditionRules.TextRules, TraditionRules.WhitespaceRules);
|
||||
@@ -33,13 +30,11 @@ public static class LetterHelpers
|
||||
return traditionState;
|
||||
}
|
||||
|
||||
public static List<(string, string, string, string, string, string)> CreateEdits(ILibrary lib, IReaderService readerService, IEnumerable<Editreason> editreasons)
|
||||
{
|
||||
public static List<(string, string, string, string, string, string)> CreateEdits(ILibrary lib, IReaderService readerService, IEnumerable<Editreason> editreasons) {
|
||||
editreasons = editreasons.OrderBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.StartPage)).ThenBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.StartLine));
|
||||
var editstrings = new List<(string, string, string, string, string, string)>();
|
||||
var editsState = new EditState();
|
||||
foreach (var edit in editreasons)
|
||||
{
|
||||
foreach (var edit in editreasons) {
|
||||
var currstring = edit.StartPage + "/" + edit.StartLine;
|
||||
var endstring = "";
|
||||
var refstring = "";
|
||||
@@ -47,10 +42,9 @@ public static class LetterHelpers
|
||||
endstring += edit.EndPage + "/" + edit.EndLine;
|
||||
else if (edit.StartLine != edit.EndLine)
|
||||
endstring += edit.EndLine;
|
||||
|
||||
|
||||
editsState.sb_edits.Append(HaWeb.HTMLHelpers.TagHelpers.CreateElement("div", "edit"));
|
||||
if (!String.IsNullOrWhiteSpace(edit.Reference))
|
||||
{
|
||||
if (!String.IsNullOrWhiteSpace(edit.Reference)) {
|
||||
var sb2 = new StringBuilder();
|
||||
sb2.Append(HaWeb.HTMLHelpers.TagHelpers.CreateElement("span", "reference"));
|
||||
var rd = readerService.RequestStringReader(edit.Reference);
|
||||
@@ -58,8 +52,7 @@ public static class LetterHelpers
|
||||
rd.Read();
|
||||
sb2.Append(HaWeb.HTMLHelpers.TagHelpers.CreateEndElement("span"));
|
||||
// Old: (edit.StartPage != edit.EndPage || edit.StartLine != edit.EndLine) &&
|
||||
if (XElement.Parse(sb2.ToString()).Value.ToString().Length >= 20)
|
||||
{
|
||||
if (XElement.Parse(sb2.ToString()).Value.ToString().Length >= 20) {
|
||||
var text = XElement.Parse(sb2.ToString()).Value.ToString();
|
||||
text = text.ToString().Split(' ').Take(1).First() + " […] " + text.ToString().Split(' ').TakeLast(1).First();
|
||||
var sb3 = new StringBuilder();
|
||||
@@ -67,12 +60,10 @@ public static class LetterHelpers
|
||||
sb3.Append(text);
|
||||
sb3.Append(HaWeb.HTMLHelpers.TagHelpers.CreateEndElement("span"));
|
||||
refstring = sb3.ToString();
|
||||
}
|
||||
else
|
||||
} else
|
||||
refstring = sb2.ToString();
|
||||
}
|
||||
if (!String.IsNullOrWhiteSpace(edit.Element))
|
||||
{
|
||||
if (!String.IsNullOrWhiteSpace(edit.Element)) {
|
||||
editsState.sb_edits.Append(HaWeb.HTMLHelpers.TagHelpers.CreateElement("span", "corrections"));
|
||||
var rd = readerService.RequestStringReader(edit.Element);
|
||||
new HaWeb.HTMLParser.XMLHelper<EditState>(editsState, rd, editsState.sb_edits, EditRules.OTagRules, EditRules.STagRules, EditRules.CTagRules, EditRules.TextRules, EditRules.WhitespaceRules);
|
||||
@@ -86,11 +77,9 @@ public static class LetterHelpers
|
||||
return editstrings;
|
||||
}
|
||||
|
||||
public static List<(string, string, string, string, string)> CreateHands(ILibrary lib, ImmutableList<Hand> hands)
|
||||
{
|
||||
public static List<(string, string, string, string, string)> CreateHands(ILibrary lib, ImmutableList<Hand> hands) {
|
||||
var handstrings = new List<(string, string, string, string, string)>();
|
||||
foreach (var hand in hands.OrderBy(x => x.StartPage.Length).ThenBy(x => x.StartPage).ThenBy(x => x.StartLine.Length).ThenBy(x => x.StartLine))
|
||||
{
|
||||
foreach (var hand in hands.OrderBy(x => x.StartPage.Length).ThenBy(x => x.StartPage).ThenBy(x => x.StartLine.Length).ThenBy(x => x.StartLine)) {
|
||||
var currstring = hand.StartPage + "/" + hand.StartLine;
|
||||
var endstring = "";
|
||||
var personstring = "";
|
||||
@@ -100,8 +89,7 @@ public static class LetterHelpers
|
||||
if (hand.StartLine != hand.EndLine)
|
||||
endstring += hand.EndLine;
|
||||
var persons = lib.HandPersons.Where(x => x.Key == hand.Person);
|
||||
if (persons.Any())
|
||||
{
|
||||
if (persons.Any()) {
|
||||
personstring += " " + persons.FirstOrDefault().Value.Name;
|
||||
handstrings.Add((currstring, endstring, personstring, hand.StartPage, hand.StartLine));
|
||||
}
|
||||
|
||||
@@ -37,21 +37,20 @@ public class LinkHelper {
|
||||
if (tag.Name == "wwwlink" || tag.Name == "intlink" || tag.Name == "link") {
|
||||
if (tag.EndTag && _followlinksinthis) {
|
||||
_sb.Append(HTMLHelpers.TagHelpers.CreateEndElement("a"));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (tag.Name == "wwwlink" && tag.Values.ContainsKey("address") && _followlinksinthis)
|
||||
_sb.Append(HTMLHelpers.TagHelpers.CreateCustomElement("a",
|
||||
new HaWeb.HTMLHelpers.TagHelpers.Attribute() { Name = "class", Value = WWWLINKCLASS },
|
||||
new HaWeb.HTMLHelpers.TagHelpers.Attribute() { Name = "href", Value = tag["address"]},
|
||||
new HaWeb.HTMLHelpers.TagHelpers.Attribute() { Name = "target", Value = "_blank"},
|
||||
new HaWeb.HTMLHelpers.TagHelpers.Attribute() { Name = "rel", Value = "noopener noreferrer"}));
|
||||
_sb.Append(HTMLHelpers.TagHelpers.CreateCustomElement("a",
|
||||
new HaWeb.HTMLHelpers.TagHelpers.Attribute() { Name = "class", Value = WWWLINKCLASS },
|
||||
new HaWeb.HTMLHelpers.TagHelpers.Attribute() { Name = "href", Value = tag["address"] },
|
||||
new HaWeb.HTMLHelpers.TagHelpers.Attribute() { Name = "target", Value = "_blank" },
|
||||
new HaWeb.HTMLHelpers.TagHelpers.Attribute() { Name = "rel", Value = "noopener noreferrer" }));
|
||||
if (tag.Name == "intlink" && tag.Values.ContainsKey("letter") && _lib.Metas.ContainsKey(tag["letter"])) {
|
||||
var letter = _lib.Metas[tag["letter"]];
|
||||
_sb.Append(HTMLHelpers.TagHelpers.CreateElement("a", LETLINKCLASS, "/Briefe/" + letter.Autopsic + "#" + tag["page"] + "-" + tag["line"]));
|
||||
if (!tag.Values.ContainsKey("linktext") || tag.Values["linktext"] == "true") {
|
||||
var linkstring = "";
|
||||
var ZHstring = "";
|
||||
var pglnstring= "";
|
||||
var pglnstring = "";
|
||||
linkstring += "HKB " + letter.Autopsic;
|
||||
if (tag.Values.ContainsKey("page")) {
|
||||
pglnstring += tag["page"];
|
||||
@@ -70,7 +69,7 @@ public class LinkHelper {
|
||||
}
|
||||
if (tag.Name == "link" && tag.Values != null) {
|
||||
Comment comment = null;
|
||||
if (tag.Values.ContainsKey("subref") && _lib.SubCommentsByID.ContainsKey(tag["subref"]))
|
||||
if (tag.Values.ContainsKey("subref") && _lib.SubCommentsByID.ContainsKey(tag["subref"]))
|
||||
comment = _lib.SubCommentsByID[tag["subref"]];
|
||||
else if (tag.Values.ContainsKey("ref"))
|
||||
if (_lib.Comments.ContainsKey(tag["ref"]))
|
||||
@@ -80,7 +79,7 @@ public class LinkHelper {
|
||||
if (comment != null) {
|
||||
var linkloc = String.IsNullOrWhiteSpace(comment.Parent) ? comment.Index : comment.Parent;
|
||||
if (_followlinksinthis)
|
||||
if (comment.Type == "neuzeit")
|
||||
if (comment.Type == "neuzeit")
|
||||
_sb.Append(HTMLHelpers.TagHelpers.CreateElement("a", REFLINKCLASS, "/Register/Register/" + linkloc[0] + "#" + comment.Index));
|
||||
else if (comment.Type == "bibel")
|
||||
_sb.Append(HTMLHelpers.TagHelpers.CreateElement("a", REFLINKCLASS, "/Register/Bibelstellen/" + linkloc[0] + linkloc[1] + "#" + comment.Index));
|
||||
|
||||
@@ -2,17 +2,15 @@ using System.Web;
|
||||
|
||||
namespace HaWeb.HTMLHelpers;
|
||||
public static class StringHelpers {
|
||||
public static string GetEnumerationString(IEnumerable<string> strlist)
|
||||
{
|
||||
public static string GetEnumerationString(IEnumerable<string> strlist) {
|
||||
var res = "";
|
||||
foreach (var str in strlist)
|
||||
{
|
||||
foreach (var str in strlist) {
|
||||
if (str != strlist.First())
|
||||
if (str == strlist.Last())
|
||||
if (str == strlist.Last())
|
||||
res += " und " + str;
|
||||
else
|
||||
res += ", " + str;
|
||||
else
|
||||
res += ", " + str;
|
||||
else
|
||||
res += str;
|
||||
}
|
||||
return res;
|
||||
|
||||
@@ -3,21 +3,18 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public static class TagHelpers
|
||||
{
|
||||
public struct Attribute
|
||||
{
|
||||
public static class TagHelpers {
|
||||
public struct Attribute {
|
||||
public string Name;
|
||||
public string Value;
|
||||
}
|
||||
|
||||
public static string CreateElement(string elementname, string classes = "", string ids = "")
|
||||
{
|
||||
public static string CreateElement(string elementname, string classes = "", string ids = "") {
|
||||
string res = "<" + elementname;
|
||||
if (!String.IsNullOrWhiteSpace(classes))
|
||||
if (elementname == "button")
|
||||
res += CreateAttribute(new Attribute() { Name = "type", Value = classes });
|
||||
else
|
||||
else
|
||||
res += CreateAttribute(new Attribute() { Name = "class", Value = classes });
|
||||
if (!String.IsNullOrWhiteSpace(ids))
|
||||
if (elementname == "a")
|
||||
@@ -27,13 +24,10 @@ public static class TagHelpers
|
||||
return res + ">";
|
||||
}
|
||||
|
||||
public static string CreateCustomElement(string elementname, params Attribute[] attributes)
|
||||
{
|
||||
public static string CreateCustomElement(string elementname, params Attribute[] attributes) {
|
||||
string res = "<" + elementname;
|
||||
if (!(attributes.Length == 0))
|
||||
{
|
||||
foreach (var attrib in attributes)
|
||||
{
|
||||
if (!(attributes.Length == 0)) {
|
||||
foreach (var attrib in attributes) {
|
||||
res += CreateAttribute(attrib);
|
||||
}
|
||||
}
|
||||
@@ -47,8 +41,7 @@ public static class TagHelpers
|
||||
public static string CreateAttribute(Attribute attr)
|
||||
=> " " + attr.Name + "=\"" + attr.Value + "\" ";
|
||||
|
||||
public static string CreateEmptyElement(string elementname, string classes = "", string ids = "")
|
||||
{
|
||||
public static string CreateEmptyElement(string elementname, string classes = "", string ids = "") {
|
||||
string res = "<" + elementname;
|
||||
if (!String.IsNullOrWhiteSpace(classes))
|
||||
res += CreateAttribute(new Attribute() { Name = "class", Value = classes });
|
||||
|
||||
Reference in New Issue
Block a user