semi-live editor
All checks were successful
Build and Deploy Client / build-and-deploy (push) Successful in 9s

This commit is contained in:
2026-08-30 01:01:54 -05:00
parent 039dc4de0c
commit b4142781dd
3 changed files with 60 additions and 12 deletions

View File

@@ -1,3 +1,7 @@
<p>markleft works!</p> <form [formGroup]="markupInput" (ngSubmit)="onSubmit()">
<textarea formControlName="inputText"></textarea>
<button>Render</button>
</form>
<div #markup_container></div>
<div #markup_container class="markup_container"></div>

View File

@@ -3,6 +3,11 @@ p {
font-size: larger; font-size: larger;
} }
.markup_container {
border: 3px solid #000000;
}
// markup classes
.format-bold { .format-bold {
font-weight: bold; font-weight: bold;
} }

View File

@@ -1,4 +1,5 @@
import { Component, ElementRef, Renderer2, ViewChild } from '@angular/core'; import { Component, ElementRef, Renderer2, ViewChild } from '@angular/core';
import { ReactiveFormsModule, FormsModule, FormControl, FormGroup, FormBuilder } from '@angular/forms';
// type descriptions // type descriptions
@@ -36,7 +37,7 @@ const styles: Record<string, formatDescriptor> = {
@Component({ @Component({
selector: 'app-markleft', selector: 'app-markleft',
imports: [], imports: [FormsModule, ReactiveFormsModule],
templateUrl: './markleft.html', templateUrl: './markleft.html',
styleUrl: './markleft.scss', styleUrl: './markleft.scss',
}) })
@@ -44,21 +45,29 @@ export class Markleft {
@ViewChild('markup_container', { static: true }) container!: ElementRef; @ViewChild('markup_container', { static: true }) container!: ElementRef;
constructor(private renderer: Renderer2) { constructor(private renderer: Renderer2, private fb: FormBuilder) {
console.log("component constructor"); console.log("component constructor");
} }
ngOnInit() { // DOM manipulation can't occur in constructor ngOnInit() { // DOM manipulation can't occur in constructor
const nodes: (textNode | blockNode)[] = this.parsePlaintext(this.plaintext); this.markupInput = this.fb.group({
console.log(nodes) inputText: [this.liveText],
nodes.forEach((node) => {
this.renderNode(node);
}); });
this.refresh();
}
markupInput = new FormGroup({
inputText: new FormControl("")
});
onSubmit() {
this.refresh();
} }
// full demo right here // full demo right here
plaintext: string = ` liveText: string = `
#H{Hello World!} #H{Hello World!}
#P{ #P{
This is some markleft text. This is %I{italic} and this is %B{bold}. Some might %I{even be %B{both}}. This is some markleft text. This is %I{italic} and this is %B{bold}. Some might %I{even be %B{both}}.
@@ -113,10 +122,13 @@ export class Markleft {
//index++; // step to next //index++; // step to next
break; break;
} else { // regular text } else { // regular text
if(input[index] !== "}") {
// hack. TODO: should probably fix because I think I'm doing something wrong
text += input[index]; text += input[index];
} }
} }
} }
}
function parseStructure(parentNode: blockNode | null = null) { function parseStructure(parentNode: blockNode | null = null) {
index++; // step onto specifier code index++; // step onto specifier code
@@ -171,10 +183,13 @@ export class Markleft {
break; break;
} else { // regular text } else { // regular text
if(input[index] !== "}") {
// hack. TODO: should probably fix because I think I'm doing something wrong
text += input[index]; text += input[index];
} }
} }
} }
}
function addTextNode(text: string, styles: string[] | null = null, parentNode: blockNode | null = null) { function addTextNode(text: string, styles: string[] | null = null, parentNode: blockNode | null = null) {
if(text.length === 0) return; if(text.length === 0) return;
@@ -210,7 +225,10 @@ export class Markleft {
// nodes.push(parseAttribute()); // nodes.push(parseAttribute());
} else { } else {
// regular character // regular character
if(input[index] !== "}") {
// hack. TODO: should probably fix because I think I'm doing something wrong
currentText += input[index]; currentText += input[index];
}
index++; index++;
} }
} }
@@ -277,4 +295,25 @@ export class Markleft {
return; return;
} }
refresh() {
if(this.markupInput.value.inputText) {
// clear children
const parent = this.container.nativeElement;
while (parent.firstChild) {
this.renderer.removeChild(parent, parent.firstChild);
}
// parse text
const nodes: (textNode | blockNode)[] = this.parsePlaintext(this.markupInput.value.inputText);
// console.log(nodes)
// render nodes
nodes.forEach((node) => {
this.renderNode(node);
});
}
}
} }