create html part 8
All checks were successful
ci / build (push) Successful in 1m6s

This commit is contained in:
Christopher Hase 2025-03-27 13:27:14 +01:00
parent d4a0e97776
commit 73b79c6aa1

109
broker.ts
View file

@ -61,26 +61,105 @@ async function sleep() {
}, 3600000);
}
function html(input: string): string {
// Zerlege den String in einzelne Zeilen
const lines = input.split("\n");
// Bearbeite jede Zeile (z.B. trimme Leerzeichen und füge einen Prefix hinzu)
//const processedLines = lines.map(line => `> ${line.trim()}`);
const processedLines = lines.map(line => processLine(line));
// Füge die Zeilen wieder zu einem String zusammen
return processedLines.join("\n");
//node structure for the Parse Tree
interface Node {
type: "Root" | "Hexagram" | "Judgement" | "Images" | "ChangingLines" ;
child?: Node;
value?: string;
//level?: number; // Für Header
}
function html(inputText: string): string {
// Parse Tree erstellen & HTML generieren
const parseTree = parse(inputText);
const htmlOutput = render(parseTree);
return htmlOutput;
}
//function parse(input: string): string {
function parse(input: string): Node {
console.log("Parse input text");
const root: Node = { type: "Root"}; //, child: {}
var currentNode: Node = root;
const lines = input.split("\n");
for (const line of lines) {
if (line.startsWith("Hexagram")) {
const hexagram: Node = { type: "Hexagram"};
currentNode.child = hexagram;
currentNode = hexagram;
currentNode.value = "<h1>" + line + "</h1>"; //TODO: formattierung
}
if (line.startsWith("Judgement")) {
const judgement: Node = { type: "Judgement"};
currentNode.child = judgement;
currentNode = judgement;
currentNode.value = "<h2>" + line + "</h2>"; //TODO: formattierung
}
if (line.startsWith("Images")) {
const images: Node = { type: "Images"};
currentNode.child = images;
currentNode = images;
currentNode.value = "<h2>" + line + "</h2>"; //TODO: formattierung
}
if (line.startsWith("changingLines") && currentNode.type != "ChangingLines") {
const changingLines: Node = { type: "ChangingLines"};
currentNode.child = changingLines;
currentNode = changingLines;
currentNode.value = line + "<br>"; //TODO: formattierung
}
else {
currentNode.value?.concat(line + "<br>");
}
}
// Bearbeite jede Zeile
//const processedLines = lines.map(line => processLine(line));
//processedLines.join("\n");
return root;
}
function render(node: Node): string {
console.log("Render node " + node.type);
var outputHTML: string = "";
// type: "Root" | "Hexagram" | "Judgement" | "Images" | "ChangingLines" ;
switch (node.type) {
case "Root":
return render(node.child!);
//case "Hexagram":
default:
outputHTML = "<p>" + node.value + "</p>";
outputHTML.concat(render(node.child!));
return outputHTML;
}
//return "";
}
/*
//TODO: process every line...
function processLine(input: string): string {
function processLine(inputLine: string): string {
if (inputLine.startsWith('Hexagram')) {
return processLineHexagram(inputLine);
}
//return input + "\n";
//"<p> ${content} </p>"
return "<p>" + input + "</p>";
return "<p>" + inputLine + "</p>";
}
function processLineHexagram(inputLine: string): string {
return "<p>" + inputLine + "</p>";
}*/