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

This commit is contained in:
Christopher Hase 2025-03-27 14:59:49 +01:00
parent 6aee5d6b9e
commit 27ceae30f0

View file

@ -77,12 +77,11 @@ function html(inputText: string): string {
return htmlOutput;
}
//function parse(input: string): string {
function parse(input: string): Node {
console.log("Parse input text");
const root: Node = { type: "Root"}; //, child: {}
const root: Node = { type: "Root"};
var currentNode: Node = root;
const lines = input.split("\n");
@ -93,52 +92,40 @@ function parse(input: string): Node {
currentNode.child = hexagram;
currentNode = hexagram;
currentNode.value = "<h1>" + line + "</h1>"; //TODO: formattierung
}
if (line.startsWith("Judgement")) {
} else 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")) {
currentNode.value = "<h2>" + line + "</h2>";
} else 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") {
if (line.startsWith("~") && currentNode.type != "ChangingLines") {
currentNode.value = "<h2>" + line + "</h2>";
} else if (line.startsWith("~") && 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>");
} else {
currentNode.value = currentNode.value + line + "<br>";
console.log("currentNode.value: " + currentNode.value);
//console.log("currentNode.value: " + currentNode.value); //TODO: zu viel Info!!!
}
}
// Bearbeite jede Zeile
//const processedLines = lines.map(line => processLine(line));
//processedLines.join("\n");
return root;
}
function render(node: Node): string {
//if (typeof node.type == "undefined") {
//if (node.type == undefined) {
if (node == undefined) {
console.log("...finished...")
return "";
}
console.log("Render node 3 " + node.type);
console.log("Render node" + node.type);
var outputHTML: string = "";
@ -149,12 +136,17 @@ function render(node: Node): string {
case "Root":
return render(node.child!);
//case "Hexagram":
default:
outputHTML = "<p>" + node.value + "</p>";
//outputHTML.concat(render(node.child!));
case "ChangingLines" :
outputHTML = "<p style=\"color: gray;\">" + node.value + "</p>";
outputHTML = outputHTML + render(node.child!);
console.log(" " + node.type + " - outputHTML: " + outputHTML);
return outputHTML;
default:
outputHTML = "<p>" + node.value + "</p>";
outputHTML = outputHTML + render(node.child!);
//console.log(" " + node.type + " - outputHTML: " + outputHTML); //TODO: zu viel Info!!!
return outputHTML;