scaffold markup
All checks were successful
Build and Deploy Client / build-and-deploy (push) Successful in 10s

This commit is contained in:
2026-08-26 23:03:58 -05:00
parent 156362a7bc
commit 8d66fe6f5f
6 changed files with 163 additions and 1 deletions

View File

@@ -0,0 +1,124 @@
import { Component } from '@angular/core';
// type descriptions
interface formatDescriptor {
className: string;
};
interface textNode {
type: string;
text: string;
styles: formatDescriptor[]
}
interface blockNode {
type: string;
kind: string;
children: (blockNode | textNode)[]
}
// styles registry: this maps format specifiers to css classes
const styles: Record<string, formatDescriptor> = {
B: {
className: "format-bold"
},
I: {
className: "format-italic"
},
U: {
className: "format-underline"
},
}; // i.e. %B{...} will apply "format-bold"
@Component({
selector: 'app-markleft',
imports: [],
templateUrl: './markleft.html',
styleUrl: './markleft.scss',
})
export class Markleft {
plaintext: String = `
#H1{Hello World!}
#P{
This is some markleft text. This is %I{italic} and this is %B{bold}. Some might %I{even be %B{both}}.
}
This should be plain and unstylized.
`;
parsePlaintext(input: string): /*structureNode[]*/ void {
/* pseudocode (c lol)
int index = 0;
void parse(char endChar = null, formatDescriptor[]) {
const nodes = []; // start with an empty list of nodes
while(index < input.length) { // iterate over the input string
// break if } encountered, step forward (this format block has exited)
if(endChar && (input[pos] == endChar)) {
index++;
break;
}
if(input[index] == "%") {
nodes.push(parseStyle(...));
} else if(input[index] == "#") {
nodes.push(parseBlock(...));
} else {
nodes.push(parseText(...));
}
return mergeAdjacentText(nodes);
}
}
void parseStyle(parentStyle) {
index++; // step onto specifier
char code = readIdentifier(input[index])
index++;
expect("{"); // parsing error if not
const styles = [...parentStyles, code] // append style code to styles list of this node
const children = parseUntil("}", styles); // recursion probably
return children
}
... and so on for parseBlock and parseText
*/
return;
}
renderNode(node: (textNode | blockNode)): void {
/*
if(node.type == "text") { // text nodes only need span elements
element span = html.createElement("span"); // or whatever it is
// add styles
foreach(style style in node.styles) {
span.classes.add(styles[style].className);
}
return span;
} else if(node.type == "block") {
element block = html.createElement(node.kind); // or whatever it is
// recursion
foreach(nodeType child in node.children) {
block.children.add(renderNode(child));
}
return block;
}
*/
return;
}
}