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

This commit is contained in:
Christopher Hase 2025-03-27 15:29:19 +01:00
parent 27ceae30f0
commit a69ae5520f

View file

@ -16,12 +16,9 @@ exec('iching divine', (error, stdout, stderr) => {
return;
}
//console.log(`Ergebnis:\n${stdout}`);
console.log(`Send E-Mail`);
sendEmail(stdout);
sleep();
});
@ -40,9 +37,7 @@ async function sendEmail(content: string) {
to: "Christopher.Hase@telekom.com;test@mailhog.local",
subject: "Your Horoscope Is Ready",
text: content,
//html: "<p> ${content} </p>"
html: html(content)
//html: content
});
console.log("E-Mail sent: ", info.messageId);
@ -61,22 +56,22 @@ async function sleep() {
}, 3600000);
}
//node structure for the Parse Tree
//node structure for the Parse Tree (it's a degenerated tree with one or zero children per node)
interface Node {
type: "Root" | "Hexagram" | "Judgement" | "Images" | "ChangingLines" ;
child?: Node;
value?: string;
//level?: number; // Für Header
}
//generate 1) Parse Tree and 2) HTML
function html(inputText: string): string {
// Parse Tree erstellen & HTML generieren
const parseTree = parse(inputText);
const htmlOutput = render(parseTree);
return htmlOutput;
}
//generate the Parse Tree
function parse(input: string): Node {
console.log("Parse input text");
@ -91,7 +86,7 @@ function parse(input: string): Node {
const hexagram: Node = { type: "Hexagram"};
currentNode.child = hexagram;
currentNode = hexagram;
currentNode.value = "<h1>" + line + "</h1>"; //TODO: formattierung
currentNode.value = "<h1>" + line + "</h1>";
} else if (line.startsWith("Judgement")) {
const judgement: Node = { type: "Judgement"};
currentNode.child = judgement;
@ -106,7 +101,7 @@ function parse(input: string): Node {
const changingLines: Node = { type: "ChangingLines"};
currentNode.child = changingLines;
currentNode = changingLines;
currentNode.value = line + "<br>"; //TODO: formattierung
currentNode.value = line + "<br>";
} else {
currentNode.value = currentNode.value + line + "<br>";
@ -117,6 +112,7 @@ function parse(input: string): Node {
return root;
}
//generate HTML from Parse Tree
function render(node: Node): string {
if (node == undefined) {
@ -135,7 +131,12 @@ function render(node: Node): string {
switch (node.type) {
case "Root":
return render(node.child!);
//case "Hexagram":
case "Hexagram":
outputHTML = "<p><i>" + node.value + "</i></p>";
outputHTML = outputHTML + render(node.child!);
return outputHTML;
case "ChangingLines" :
outputHTML = "<p style=\"color: gray;\">" + node.value + "</p>";
outputHTML = outputHTML + render(node.child!);