i think this is a good checkpoint
All checks were successful
Build and Deploy Client / build-and-deploy (push) Successful in 10s
All checks were successful
Build and Deploy Client / build-and-deploy (push) Successful in 10s
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
|
||||
.format-plain {
|
||||
// empty on purpose
|
||||
color: #000000;
|
||||
p {
|
||||
font-size: larger;
|
||||
}
|
||||
|
||||
.format-bold {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user