Added a few comments
This commit is contained in:
parent
7651fd4c7b
commit
4ba222c8c8
|
|
@ -8,36 +8,45 @@ const Article = ({article}) => {
|
||||||
let ind = 0;
|
let ind = 0;
|
||||||
let tick=false;
|
let tick=false;
|
||||||
|
|
||||||
for (let i = 0; i < text.length; i++) {
|
for (let i = 0; i < text.length; i++) { // Iterate through input
|
||||||
if (text[i] === '`') {
|
if (text[i] === '`') { // Detect Code Delimiter
|
||||||
if (tick) {
|
if (tick) { // Close the code section
|
||||||
//output[ind++] += text[i]
|
|
||||||
output[++ind] = ""
|
output[++ind] = ""
|
||||||
tick = false;
|
tick = false;
|
||||||
} else {
|
|
||||||
//output[++ind] = text[i]
|
} else { // Start a new code section
|
||||||
|
|
||||||
type.push(1);
|
type.push(1);
|
||||||
output[++ind] = ""
|
output[++ind] = ""
|
||||||
tick = true;
|
tick = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else { // Append text to output
|
||||||
if (output.length > type.length) {
|
|
||||||
|
if (output.length > type.length) { // If this is the beggining of a default text type
|
||||||
type.push(0);
|
type.push(0);
|
||||||
output[ind] = ""
|
output[ind] = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
output[ind] += text[i]
|
output[ind] += text[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let code = [...output.keys()].map((i)=>{
|
|
||||||
console.log(output[i], type[i]);
|
return [...output.keys()].map((i)=>{ // Format text and return as jsx
|
||||||
if (type[i] == 0){
|
|
||||||
|
|
||||||
|
if (type[i] === 0){ // Return default text type
|
||||||
|
|
||||||
return <div key={i}>{output[i]}</div>;
|
return <div key={i}>{output[i]}</div>;
|
||||||
} else {
|
|
||||||
|
} else if(type[i] == 1) { // Return Code text type
|
||||||
|
|
||||||
return <div className="code" key={i}>{output[i]}</div>;
|
return <div className="code" key={i}>{output[i]}</div>;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return code
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue