From a69ae5520f3d4744b2f672aec36e86dc4c00eef1 Mon Sep 17 00:00:00 2001 From: Christopher Hase Date: Thu, 27 Mar 2025 15:29:19 +0100 Subject: [PATCH] create html part 16 --- broker.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/broker.ts b/broker.ts index 0a74069..88acc9d 100644 --- a/broker.ts +++ b/broker.ts @@ -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: "

${content}

" 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 = "

" + line + "

"; //TODO: formattierung + currentNode.value = "

" + line + "

"; } 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 + "
"; //TODO: formattierung + currentNode.value = line + "
"; } else { currentNode.value = currentNode.value + line + "
"; @@ -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 = "

" + node.value + "

"; + outputHTML = outputHTML + render(node.child!); + + return outputHTML; + case "ChangingLines" : outputHTML = "

" + node.value + "

"; outputHTML = outputHTML + render(node.child!);