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 {
|
p {
|
||||||
// empty on purpose
|
font-size: larger;
|
||||||
color: #000000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.format-bold {
|
.format-bold {
|
||||||
|
|||||||
@@ -109,17 +109,8 @@ export class Markleft {
|
|||||||
// and then move to the next
|
// and then move to the next
|
||||||
parseStyle(parentNode ? parentNode : null, styles); // recursion
|
parseStyle(parentNode ? parentNode : null, styles); // recursion
|
||||||
} else if(input[index] == "}") { // this node has closed
|
} else if(input[index] == "}") { // this node has closed
|
||||||
if(text.length === 0) break; // an empty text block is to be ignored
|
addTextNode(text, styles, parentNode);
|
||||||
const node: textNode = {
|
//index++; // step to next
|
||||||
type: "text",
|
|
||||||
text: text,
|
|
||||||
styles: styles
|
|
||||||
};
|
|
||||||
if(parentNode) {
|
|
||||||
parentNode.children.push(node);
|
|
||||||
} else {
|
|
||||||
nodes.push(node);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
} else { // regular text
|
} else { // regular text
|
||||||
text += input[index];
|
text += input[index];
|
||||||
@@ -137,19 +128,19 @@ export class Markleft {
|
|||||||
}
|
}
|
||||||
console.log("Parsing structure for format specifier", code);
|
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 = "";
|
let text: string = "";
|
||||||
while(true) { // assemble text
|
while(true) { // assemble text
|
||||||
index++;
|
index++;
|
||||||
if(input[index] === "%" || input[index] === "#") { // encountered another format specifier
|
if(input[index] === "%" || input[index] === "#") { // encountered another format specifier
|
||||||
|
|
||||||
// create the node
|
// commit current plain text to the block
|
||||||
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
|
|
||||||
if(text.length !== 0) {
|
if(text.length !== 0) {
|
||||||
const textNode: textNode = {
|
const textNode: textNode = {
|
||||||
type: "text",
|
type: "text",
|
||||||
@@ -158,12 +149,6 @@ export class Markleft {
|
|||||||
};
|
};
|
||||||
node.children.push(textNode);
|
node.children.push(textNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parentNode) {
|
|
||||||
parentNode.children.push(node);
|
|
||||||
} else {
|
|
||||||
nodes.push(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
text = ""; // clear the already commited text
|
text = ""; // clear the already commited text
|
||||||
// and then move to the next
|
// and then move to the next
|
||||||
@@ -173,21 +158,17 @@ export class Markleft {
|
|||||||
parseStructure(node);
|
parseStructure(node);
|
||||||
}
|
}
|
||||||
} else if(input[index] == "}") { // this node has closed
|
} else if(input[index] == "}") { // this node has closed
|
||||||
|
index++;
|
||||||
// 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
|
|
||||||
};
|
|
||||||
// add its text
|
// add its text
|
||||||
const textNode: textNode = {
|
addTextNode(text, null, node);
|
||||||
type: "text",
|
|
||||||
text: text,
|
// push node to children list
|
||||||
styles: [] // none in this case
|
if(parentNode) {
|
||||||
};
|
parentNode.children.push(node);
|
||||||
node.children.push(textNode);
|
} else {
|
||||||
nodes.push(node);
|
nodes.push(node);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} else { // regular text
|
} else { // regular text
|
||||||
text += input[index];
|
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) {
|
function parse(endChar: string | null = null) {
|
||||||
console.log("parsing...");
|
console.log("parsing...");
|
||||||
|
let currentText: string = "";
|
||||||
while(index < input.length) {
|
while(index < input.length) {
|
||||||
if(endChar && (input[index] === endChar)) {
|
if(endChar && (input[index] === endChar)) {
|
||||||
index++;
|
index++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(input[index] === "%") { // encountered a style specifier
|
if(input[index] === "%") { // encountered a style specifier
|
||||||
|
addTextNode(currentText);
|
||||||
parseStyle();
|
parseStyle();
|
||||||
|
currentText = "";
|
||||||
} else if(input[index] === "#") { // encountered a structure specifier
|
} else if(input[index] === "#") { // encountered a structure specifier
|
||||||
|
addTextNode(currentText);
|
||||||
parseStructure();
|
parseStructure();
|
||||||
|
currentText = "";
|
||||||
} else if(input[index] === "@") { // encountered an attribute specifier
|
} else if(input[index] === "@") { // encountered an attribute specifier
|
||||||
// nodes.push(parseAttribute());
|
// nodes.push(parseAttribute());
|
||||||
} else {
|
} else {
|
||||||
// regular character
|
// regular character
|
||||||
|
currentText += input[index];
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
addTextNode(currentText);
|
||||||
}
|
}
|
||||||
|
|
||||||
parse();
|
parse();
|
||||||
|
|||||||
Reference in New Issue
Block a user