diff --git a/src/components/Article.js b/src/components/Article.js index 6b32443..3f2a4a2 100644 --- a/src/components/Article.js +++ b/src/components/Article.js @@ -3,12 +3,45 @@ import Theater from './subcomponents/Theater'; import './css/Articles.css'; const Article = ({article}) => { + let linkProcessor = (text) => { + /** + * Given some text, processes and returns jsx with any link represented as an anchor + */ + + let output = [""]; // Stores all text in a list + let loc = 0; // Stores the current location in output that we're working with + + for (let i = 0; i < text.length; i++) { // Iterate through the entire text string + if (text.slice(i, i+4) === "http"){ // slice from i to 4 chars plus and check for http + let x = i; // store i in x so the location is not modified + + for (i; text[i] != " " && i < text.length; i++){} // iterate until we find the end of the link denoted by a space + + if (output[loc] !== "") { // if the current output location isn't empty, increment loc + loc++; + } + + // Put anchor for link into output list + output[loc] = {text.slice(x, i)}; + output[++loc] = ""; // Create new location in output with empty string + + } else { + // Append current char to output + output[loc] += text[i]; + + } + } + + // Return the output + return output; + }; + let articleFormatter = (text) => { - let output = []; - let type = []; - let ind = 0; - let tick=false; - let delimiters = ['', '`', '*', '~']; + let output = []; // Used to store separate formatted text + let type = []; // Parallel to output list to signify format type + let ind = 0; // Denote index of output + let tick=false; // used to check if we're currently in formatted text. + let delimiters = ['', '`', '*', '~']; // Denotes characters used to format for (let i = 0; i < text.length; i++) { // Iterate through input if (delimiters.indexOf(text[i]) !== -1) { // Detect Code Delimiter @@ -49,22 +82,23 @@ const Article = ({article}) => { return [...output.keys()].map((i)=>{ // Format text and return as jsx + let text = linkProcessor(output[i]); // Process links if (type[i] === 0){ // Return default text type - return