From 039dc4de0c5a242f908e3181c95397bfcfa39e0d Mon Sep 17 00:00:00 2001 From: Preston McGee Date: Sat, 29 Aug 2026 23:47:59 -0500 Subject: [PATCH] i think this is a good checkpoint --- client/src/app/markleft/markleft.scss | 5 +- client/src/app/markleft/markleft.ts | 80 ++++++++++++++------------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/client/src/app/markleft/markleft.scss b/client/src/app/markleft/markleft.scss index e575a9c..0c6eeab 100644 --- a/client/src/app/markleft/markleft.scss +++ b/client/src/app/markleft/markleft.scss @@ -1,7 +1,6 @@ -.format-plain { - // empty on purpose - color: #000000; +p { + font-size: larger; } .format-bold { diff --git a/client/src/app/markleft/markleft.ts b/client/src/app/markleft/markleft.ts index d0f6c0c..b06bf5f 100644 --- a/client/src/app/markleft/markleft.ts +++ b/client/src/app/markleft/markleft.ts @@ -109,17 +109,8 @@ export class Markleft { // and then move to the next parseStyle(parentNode ? parentNode : null, styles); // recursion } else if(input[index] == "}") { // this node has closed - if(text.length === 0) break; // an empty text block is to be ignored - const node: textNode = { - type: "text", - text: text, - styles: styles - }; - if(parentNode) { - parentNode.children.push(node); - } else { - nodes.push(node); - } + addTextNode(text, styles, parentNode); + //index++; // step to next break; } else { // regular text text += input[index]; @@ -137,19 +128,19 @@ export class Markleft { } console.log("Parsing structure for format specifier", code); + // create the node + const node: blockNode = { + type: "block", + kind: code, + children: [] // this blockNode will get passed to children so they can be added to the parent + }; + let text: string = ""; while(true) { // assemble text index++; if(input[index] === "%" || input[index] === "#") { // encountered another format specifier - // create the node - const node: blockNode = { - type: "block", - kind: code, - children: [] // this blockNode will get passed to children so they can be added to the parent - }; - - // commit text to the block + // commit current plain text to the block if(text.length !== 0) { const textNode: textNode = { type: "text", @@ -158,12 +149,6 @@ export class Markleft { }; node.children.push(textNode); } - - if(parentNode) { - parentNode.children.push(node); - } else { - nodes.push(node); - } text = ""; // clear the already commited text // and then move to the next @@ -173,21 +158,17 @@ export class Markleft { parseStructure(node); } } else if(input[index] == "}") { // this node has closed - - // create the node - const node: blockNode = { - type: "block", - kind: code, - children: [] // this blockNode will get passed to children so they can be added to the parent - }; + index++; // add its text - const textNode: textNode = { - type: "text", - text: text, - styles: [] // none in this case - }; - node.children.push(textNode); - nodes.push(node); + addTextNode(text, null, node); + + // push node to children list + if(parentNode) { + parentNode.children.push(node); + } else { + nodes.push(node); + } + break; } else { // regular text text += input[index]; @@ -195,24 +176,45 @@ export class Markleft { } } + function addTextNode(text: string, styles: string[] | null = null, parentNode: blockNode | null = null) { + if(text.length === 0) return; + const textNode: textNode = { + type: "text", + text: text, + styles: styles ? styles : [] + } + if(parentNode) { + parentNode.children.push(textNode); + } else { + nodes.push(textNode); + } + } + function parse(endChar: string | null = null) { console.log("parsing..."); + let currentText: string = ""; while(index < input.length) { if(endChar && (input[index] === endChar)) { index++; break; } if(input[index] === "%") { // encountered a style specifier + addTextNode(currentText); parseStyle(); + currentText = ""; } else if(input[index] === "#") { // encountered a structure specifier + addTextNode(currentText); parseStructure(); + currentText = ""; } else if(input[index] === "@") { // encountered an attribute specifier // nodes.push(parseAttribute()); } else { // regular character + currentText += input[index]; index++; } } + addTextNode(currentText); } parse();