diff --git a/broker.ts b/broker.ts index b85190e..e7a0a4b 100644 --- a/broker.ts +++ b/broker.ts @@ -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 = "
" + node.value + "
"; + 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"; //"${content}
" - return "" + input + "
"; + return "" + inputLine + "
"; } + +function processLineHexagram(inputLine: string): string { + + return "" + inputLine + "
"; +}*/ \ No newline at end of file