create html part 8
This commit is contained in:
parent
d4a0e97776
commit
73b79c6aa1
1 changed files with 94 additions and 15 deletions
109
broker.ts
109
broker.ts
|
@ -61,26 +61,105 @@ async function sleep() {
|
||||||
}, 3600000);
|
}, 3600000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//node structure for the Parse Tree
|
||||||
|
interface Node {
|
||||||
function html(input: string): string {
|
type: "Root" | "Hexagram" | "Judgement" | "Images" | "ChangingLines" ;
|
||||||
|
child?: Node;
|
||||||
// Zerlege den String in einzelne Zeilen
|
value?: string;
|
||||||
const lines = input.split("\n");
|
//level?: number; // Für Header
|
||||||
|
|
||||||
// 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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 = "<h1>" + line + "</h1>"; //TODO: formattierung
|
||||||
|
}
|
||||||
|
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")) {
|
||||||
|
const images: Node = { type: "Images"};
|
||||||
|
currentNode.child = images;
|
||||||
|
currentNode = images;
|
||||||
|
currentNode.value = "<h2>" + line + "</h2>"; //TODO: formattierung
|
||||||
|
}
|
||||||
|
if (line.startsWith("changingLines") && 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>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bearbeite jede Zeile
|
||||||
|
//const processedLines = lines.map(line => processLine(line));
|
||||||
|
//processedLines.join("\n");
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
function render(node: Node): string {
|
||||||
|
|
||||||
|
console.log("Render node " + node.type);
|
||||||
|
|
||||||
|
var outputHTML: string = "";
|
||||||
|
|
||||||
|
// type: "Root" | "Hexagram" | "Judgement" | "Images" | "ChangingLines" ;
|
||||||
|
switch (node.type) {
|
||||||
|
case "Root":
|
||||||
|
return render(node.child!);
|
||||||
|
//case "Hexagram":
|
||||||
|
default:
|
||||||
|
outputHTML = "<p>" + node.value + "</p>";
|
||||||
|
outputHTML.concat(render(node.child!));
|
||||||
|
return outputHTML;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
//TODO: process every line...
|
//TODO: process every line...
|
||||||
function processLine(input: string): string {
|
function processLine(inputLine: string): string {
|
||||||
|
|
||||||
|
if (inputLine.startsWith('Hexagram')) {
|
||||||
|
return processLineHexagram(inputLine);
|
||||||
|
}
|
||||||
|
|
||||||
//return input + "\n";
|
//return input + "\n";
|
||||||
//"<p> ${content} </p>"
|
//"<p> ${content} </p>"
|
||||||
return "<p>" + input + "</p>";
|
return "<p>" + inputLine + "</p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processLineHexagram(inputLine: string): string {
|
||||||
|
|
||||||
|
return "<p>" + inputLine + "</p>";
|
||||||
|
}*/
|
||||||
|
|
Loading…
Reference in a new issue