mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 17:25:32 +00:00
- Abstracted the XML-HTML Parser into a neat little state machine
- Added Settings classes for all things XML-HTML conversion
This commit is contained in:
6
HaWeb/Settings/ParsingState/CommentState.cs
Normal file
6
HaWeb/Settings/ParsingState/CommentState.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace HaWeb.Settings.ParsingState;
|
||||
using System.Text;
|
||||
|
||||
public class CommentState : HaWeb.HTMLParser.IState {
|
||||
public void SetupState() { }
|
||||
}
|
||||
19
HaWeb/Settings/ParsingState/EditState.cs
Normal file
19
HaWeb/Settings/ParsingState/EditState.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace HaWeb.Settings.ParsingState;
|
||||
using System.Text;
|
||||
|
||||
public class EditState : HaWeb.HTMLParser.IState {
|
||||
internal bool active_del;
|
||||
internal bool active_skipwhitespace;
|
||||
|
||||
internal StringBuilder sb_edits;
|
||||
|
||||
public EditState() {
|
||||
SetupState();
|
||||
}
|
||||
|
||||
public void SetupState() {
|
||||
sb_edits = new StringBuilder();
|
||||
active_del = false;
|
||||
active_skipwhitespace = true;
|
||||
}
|
||||
}
|
||||
60
HaWeb/Settings/ParsingState/LetterState.cs
Normal file
60
HaWeb/Settings/ParsingState/LetterState.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
namespace HaWeb.Settings.ParsingState;
|
||||
|
||||
using HaDocument.Interfaces;
|
||||
using HaXMLReader.Interfaces;
|
||||
using HaXMLReader.EvArgs;
|
||||
using HaDocument.Models;
|
||||
using System.Text;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public class LetterState : HaWeb.HTMLParser.IState {
|
||||
// Input
|
||||
internal ILibrary Lib;
|
||||
internal IReaderService ReaderService;
|
||||
internal Meta Meta;
|
||||
|
||||
internal IEnumerable<Marginal>? Marginals;
|
||||
|
||||
// State
|
||||
internal bool active_del;
|
||||
internal bool active_skipwhitespace;
|
||||
internal string currline;
|
||||
internal string currpage;
|
||||
internal string oldpage;
|
||||
internal int commid;
|
||||
|
||||
// Parsing-Combinations
|
||||
internal StringBuilder sb_lettertext; // Hauptext
|
||||
internal StringBuilder sb_linecount; // Linke Spalte (Zeilenzählung)
|
||||
internal StringBuilder sb_marginals; // Rechte Spalte (Kommentare)
|
||||
|
||||
|
||||
public LetterState(ILibrary lib, IReaderService readerService, Meta meta, IEnumerable<Marginal>? marginals) {
|
||||
Lib = lib;
|
||||
ReaderService = readerService;
|
||||
Meta = meta;
|
||||
Marginals = marginals;
|
||||
|
||||
SetupState();
|
||||
}
|
||||
|
||||
|
||||
public void SetupState() {
|
||||
sb_lettertext = new StringBuilder();
|
||||
sb_linecount = new StringBuilder();
|
||||
sb_marginals = new StringBuilder();
|
||||
|
||||
active_skipwhitespace = true;
|
||||
currline = "-1";
|
||||
currpage = "";
|
||||
oldpage = "";
|
||||
commid = 1;
|
||||
|
||||
// Initialize State
|
||||
if (Meta.ZH != null) {
|
||||
currpage = Meta.ZH.Page;
|
||||
}
|
||||
}
|
||||
}
|
||||
6
HaWeb/Settings/ParsingState/LinkState.cs
Normal file
6
HaWeb/Settings/ParsingState/LinkState.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace HaWeb.Settings.ParsingState;
|
||||
using System.Text;
|
||||
|
||||
public class LinkState : HaWeb.HTMLParser.IState {
|
||||
public void SetupState() { }
|
||||
}
|
||||
54
HaWeb/Settings/ParsingState/TraditionState.cs
Normal file
54
HaWeb/Settings/ParsingState/TraditionState.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
namespace HaWeb.Settings.ParsingState;
|
||||
using System.Text;
|
||||
using HaXMLReader.Interfaces;
|
||||
using HaDocument.Models;
|
||||
using HaDocument.Interfaces;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
public class TraditionState : HaWeb.HTMLParser.IState {
|
||||
|
||||
internal ILibrary Lib;
|
||||
internal IReaderService ReaderService;
|
||||
|
||||
internal IEnumerable<Marginal>? Marginals;
|
||||
|
||||
internal bool active_del;
|
||||
internal bool active_skipwhitespace;
|
||||
internal bool active_firstedit;
|
||||
internal string currline;
|
||||
internal string currpage;
|
||||
internal string oldpage;
|
||||
internal int commid;
|
||||
internal bool active_trad;
|
||||
|
||||
internal StringBuilder sb_tradition; // Überlieferung
|
||||
internal StringBuilder sb_trad_zhtext; // Überlieferung, ZHText
|
||||
internal StringBuilder sb_trad_left; // Überlieferung ZHText linke Spalte (zeilenzählung)
|
||||
internal StringBuilder sb_trad_right; // Überlieferung ZHText rechte Spalte (Kommentare)
|
||||
|
||||
internal IReader rd_tradition;
|
||||
|
||||
public TraditionState(ILibrary lib, IReader reader, IEnumerable<Marginal>? marginals)
|
||||
{
|
||||
Lib = lib;
|
||||
rd_tradition = reader;
|
||||
Marginals = marginals;
|
||||
SetupState();
|
||||
}
|
||||
|
||||
public void SetupState() {
|
||||
sb_tradition = new StringBuilder();
|
||||
sb_trad_zhtext = new StringBuilder();
|
||||
sb_trad_left = new StringBuilder();
|
||||
sb_trad_right = new StringBuilder();
|
||||
|
||||
active_trad = false;
|
||||
active_del = false;
|
||||
active_skipwhitespace = true;
|
||||
active_firstedit = true;
|
||||
currline = "-1";
|
||||
currpage = "";
|
||||
oldpage = "";
|
||||
commid = 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user