function newEducationUtilitiesDocs() {
let thisObject = {
buildOrderedPageIndex: buildOrderedPageIndex,
addWarningIfTranslationIsOutdated: addWarningIfTranslationIsOutdated,
getTextBasedOnLanguage: getTextBasedOnLanguage,
setTextBasedOnLanguage: setTextBasedOnLanguage,
parseGIF: parseGIF,
reverseParseGIF: reverseParseGIF,
parsePNG: parsePNG,
reverseParsePNG: reverseParsePNG,
parseTable: parseTable,
parseLink: parseLink,
parseYoutube: parseYoutube,
reverseParseLink: reverseParseLink,
reverseParseYoutube: reverseParseYoutube,
reverseParseHierarchy: reverseParseHierarchy,
reverseParseTable: reverseParseTable,
addBold: addBold,
addKeyboard: addKeyboard,
addCodeToCamelCase: addCodeToCamelCase,
addCodeToWhiteList: addCodeToWhiteList,
addItalics: addItalics,
addToolTips: addToolTips
}
const TAGGING_STRING_SEPARATOR = '~>'
return thisObject
function buildOrderedPageIndex(project, category, query) {
let array = []
let schemaArray
switch (category) {
case 'Topic': {
schemaArray = SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema
break
}
case 'Tutorial': {
schemaArray = SCHEMAS_BY_PROJECT.get(project).array.docsTutorialSchema
break
}
case 'Review': {
schemaArray = SCHEMAS_BY_PROJECT.get(project).array.docsReviewSchema
break
}
}
for (let i = 0; i < schemaArray.length; i++) {
let arrayItem = schemaArray[i]
switch (category) {
case 'Topic': {
if (arrayItem.topic !== query) { continue }
break
}
case 'Tutorial': {
if (arrayItem.tutorial !== query) { continue }
break
}
case 'Review': {
if (arrayItem.review !== query) { continue }
break
}
}
let itemAdded = false
if (array.length === 0) {
array.push(arrayItem)
itemAdded = true
} else {
for (let j = 0; j < array.length; j++) {
let orderedArrayItem = array[j]
if (Number(arrayItem.pageNumber) < Number(orderedArrayItem.pageNumber)) {
array.splice(j, 0, arrayItem)
itemAdded = true
break
}
}
}
if (itemAdded === false) {
array.push(arrayItem)
}
}
return array
}
function addWarningIfTranslationIsOutdated(paragraph) {
if (paragraph === undefined) { return '' }
if (paragraph.updated === undefined) { return '' }
if (paragraph.translations === undefined) { return '' }
if (paragraph.translations.length === 0) { return '' }
for (let i = 0; i < paragraph.translations.length; i++) {
let translation = paragraph.translations[i]
if (translation.updated === undefined) { continue }
if (translation.language === UI.projects.education.spaces.docsSpace.language) {
if (paragraph.updated < translation.updated) {
return ''
} else {
return ' Warning!!! This translation is outdated. English version is... ' + paragraph.text + ' Please update this translation.'
}
}
}
return ''
}
function getTextBasedOnLanguage(paragraph) {
if (paragraph === undefined) { return }
if (paragraph.translations === undefined) { return paragraph.text }
if (paragraph.translations.length === 0) { return paragraph.text }
for (let i = 0; i < paragraph.translations.length; i++) {
let translation = paragraph.translations[i]
if (translation.language === UI.projects.education.spaces.docsSpace.language) { return translation.text }
}
return paragraph.text
}
function setTextBasedOnLanguage(paragraph, text) {
if (UI.projects.education.spaces.docsSpace.language === UI.projects.education.globals.docs.DEFAULT_LANGUAGE) {
if (paragraph.text !== text) {
/* This will make the Client to save this in a file overwriting the previous version*/
UI.projects.education.spaces.docsSpace.documentPage.docsSchemaDocument.updated = true
paragraph.text = text
paragraph.updated = (new Date()).valueOf()
}
return
} else {
/*
We will avoid setting up a new language if the text is
the same as the text at the default language.
*/
if (paragraph.text === text) {
return
}
}
if (paragraph.translations === undefined) {
paragraph.translations = []
}
for (let i = 0; i < paragraph.translations.length; i++) {
let translation = paragraph.translations[i]
if (translation.language === UI.projects.education.spaces.docsSpace.language) {
if (translation.text !== text) {
/* This will make the Client to save this in a file overwriting the previous version*/
UI.projects.education.spaces.docsSpace.documentPage.docsSchemaDocument.updated = true
translation.text = text
translation.updated = (new Date()).valueOf()
}
return
}
}
let translation = {
language: UI.projects.education.spaces.docsSpace.language,
text: text,
updated: (new Date()).valueOf()
}
paragraph.translations.push(translation)
/* This will make the Client to save this in a file overwriting the previous version*/
UI.projects.education.spaces.docsSpace.documentPage.docsSchemaDocument.updated = true
return
}
function parseGIF(text) {
return ''
}
function reverseParseGIF(HTML) {
let result = HTML
result = result.replace('
', '')
return result.trim()
}
function parsePNG(text) {
return '
'
}
function reverseParsePNG(HTML) {
let result = HTML
result = result.replace('
', '')
return result.trim()
}
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 + ''
}
if (i === 1) {
HTML = HTML + '
' + word + ''
}
if (i === 0) {
result = word
} else {
result = result + ' ' + word
}
}
result = result
.replaceAll(' { ', '{')
.replaceAll(' } ', '}')
.replaceAll(' ( ', '(')
.replaceAll(' ) ', ')')
.replaceAll(' [ ', '[')
.replaceAll(' ] ', ']')
.replaceAll(' , ', ',')
return result
}
function addCodeToWhiteList(text) {
let result = text
.replaceAll('true', 'true')
.replaceAll('false', 'false')
return result
}
function addItalics(text) {
let cleanText = text.replace(/'/g, ' AMPERSAND ') // scaping ampersands, separating them from other words
let words = cleanText.split(' ')
let changedText = ''
for (let i = 0; i < words.length; i++) {
let phrase1 = words[i]
let phrase2 = words[i] + ' ' + words[i + 1]
let phrase3 = words[i] + ' ' + words[i + 1] + ' ' + words[i + 2]
let phrase4 = words[i] + ' ' + words[i + 1] + ' ' + words[i + 2] + ' ' + words[i + 3]
let cleanPhrase1 = cleanPhrase(phrase1)
let cleanPhrase2 = cleanPhrase(phrase2)
let cleanPhrase3 = cleanPhrase(phrase3)
let cleanPhrase4 = cleanPhrase(phrase4)
let found = false
if (found === false && UI.projects.education.spaces.docsSpace.menuLabelsMap.get(cleanPhrase4) === true) {
changedText = changedText + phrase4.replace(cleanPhrase4, '' + cleanPhrase4 + '') + ' '
i = i + 3
found = true
}
if (found === false && UI.projects.education.spaces.docsSpace.menuLabelsMap.get(cleanPhrase3) === true) {
changedText = changedText + phrase3.replace(cleanPhrase3, '' + cleanPhrase3 + '') + ' '
i = i + 2
found = true
}
if (found === false && UI.projects.education.spaces.docsSpace.menuLabelsMap.get(cleanPhrase2) === true) {
changedText = changedText + phrase2.replace(cleanPhrase2, '' + cleanPhrase2 + '') + ' '
i = i + 1
found = true
}
if (found === false && UI.projects.education.spaces.docsSpace.menuLabelsMap.get(cleanPhrase1) === true) {
changedText = changedText + phrase1.replace(cleanPhrase1, '' + cleanPhrase1 + '') + ' '
i = i + 0
found = true
}
if (found === false) {
changedText = changedText + phrase1 + ' '
}
}
changedText = changedText.replaceAll(' AMPERSAND ', '\'')
return changedText
}
function addToolTips(text, excludedType) {
const TOOL_TIP_HTML = '