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