diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js index c425b4b4e..9449d2f30 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js @@ -380,7 +380,7 @@ function newSuperalgosDocSpace() { for (let i = 1; i < 10; i++) { if (paragraphNode.id === undefined || paragraphNode.id.indexOf('paragraph') < 0) { paragraphNode = paragraphNode.parentNode - if (paragraphNode === undefined) { return false} + if (paragraphNode === undefined) { return false } } } if (paragraphNode.id === undefined || paragraphNode.id.indexOf('paragraph') < 0) { @@ -1428,9 +1428,21 @@ function newSuperalgosDocSpace() { function parseTable(text) { let HTML = '' let odd = false + /* When the text is not formatted as a table, we auto format it as a single cell table */ + if (text.indexOf('|') < 0) { + text = "|" + text + "|" + } + + /* We process the text based table*/ let rows = text.split(String.fromCharCode(10)) for (let i = 0; i < rows.length; i++) { let row = rows[i] + if (row === '') { + if (i === rows.length - 1) { + HTML = HTML + '' + } + continue + } let colums = row.split('|') if (i === 0) { HTML = HTML + '' @@ -1446,7 +1458,7 @@ function newSuperalgosDocSpace() { odd = true } if (colums.length < 2) { - return text + continue } else { /* We discard anything before the first | and after the last | */ for (let j = 1; j < colums.length - 1; j++) { @@ -1467,28 +1479,54 @@ function newSuperalgosDocSpace() { HTML = HTML + '' } } + HTML = addRGB(HTML) return HTML - } + function addRGB(text) { + const RGB_HTML = '
HOLA 
' + let splittedText = text.split('RGB(') + if (splittedText.length === 1) { return text } + let remainderSplit = splittedText[1].split(')') + if (remainderSplit.length === 1) { return text } + let RGBFound = 'RGB(' + remainderSplit[0] + ')' + let span = RGB_HTML.replace('RGB', RGBFound) + let result = text.replace(RGBFound, span) + return result + } + } + // style=\"display: block; background: RGB; border: 1px solid black;\" function reverseParseTable(HTML) { - text = HTML + text = removeRGB(HTML) + + /* Single occurrance replacements */ text = text.replace(' ', '') text = text.replace('
', '') text = text.replace('', '') text = text.replace('', '') text = text.replace('', '') - text = text.replace('', '') + text = text.replace('', '') + /* All instances replacements */ text = text.replaceAll('', '') text = text.replaceAll('', '') text = text.replaceAll('', '|') text = text.replaceAll('', '|') - text = text.replaceAll('', String.fromCharCode(10)) text = text.replaceAll('', '|') text = text.replaceAll('', '|') text = text.replaceAll('', '|') text = text.replaceAll('', '|') + text = text.replaceAll('', '') + + /* We break lines where needed */ + text = text.replaceAll('||', '|' + String.fromCharCode(10) + '|') return text + + function removeRGB(HTML) { + let text = HTML + text.replace(' ', '') + return text + } } function addBold(text) {