aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils
diff options
context:
space:
mode:
authorcaleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu>2022-03-21 17:26:05 -0400
committercaleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu>2022-03-21 17:26:05 -0400
commit79db229a94aa3f407399158470e3d027d2b035e8 (patch)
tree0cdf0a3da7f9ab0289cef047167c3a75e7eb2ab9 /webAO/utils
parent27e9271bf46016a77d4f9e9ce654a6be2aceaed1 (diff)
Fixing bugs
Diffstat (limited to 'webAO/utils')
-rw-r--r--webAO/utils/aoml.js48
1 files changed, 38 insertions, 10 deletions
diff --git a/webAO/utils/aoml.js b/webAO/utils/aoml.js
index 6c4cafb..9506fbf 100644
--- a/webAO/utils/aoml.js
+++ b/webAO/utils/aoml.js
@@ -43,9 +43,12 @@ const mlConfig = (AO_HOST) => {
if (identifiers.has(value.start)) {
throw new Error()
}
- else if (value.start) {
- identifiers.set(value.start, value.end)
+ else if (value.start && value.end) {
+ identifiers.set(value.start, value)
+ identifiers.set(value.end, value)
}
+
+
}
return identifiers
}
@@ -56,38 +59,63 @@ const mlConfig = (AO_HOST) => {
}
return colorIdentifier
}
- const applyMarkdown = (text) => {
+ const applyMarkdown = (text, defaultColor) => {
const identifiers = createIdentifiers(aomlParsed)
const startIdentifiers = new Set(identifiers.keys())
const colorIdentifier = colorIdentifiers()
const identifierClosingStack = []
+
const colorStack = [[255, 255, 255]]
// each value in output will be an html element
let output = []
for (const letter of text) {
let currentSelector = document.createElement('span')
-
+ let letterIdentifier = identifiers.get(letter)
const lastItem = identifierClosingStack.length
const closingToLookFor = identifierClosingStack[lastItem-1]
+ const keepChar = Number(letterIdentifier?.remove) === 0
+
if (letter === closingToLookFor) {
identifierClosingStack.pop()
+ if (keepChar) {
+ currentSelector.innerHTML = letter
+ if (colorStack.length === 1){
+ currentSelector.className = `text_${defaultColor}`
+ } else {
+ const r = colorStack[colorStack.length-1][0]
+ const g = colorStack[colorStack.length-1][1]
+ const b = colorStack[colorStack.length-1][2]
+ const currentColor = `color: rgb(${r},${g},${b});`
+ currentSelector.setAttribute('style', currentColor)
+ }
+ output.push(currentSelector)
+ }
colorStack.pop()
+ continue;
}
else if (startIdentifiers.has(letter)) {
- identifierClosingStack.push(identifiers.get(letter))
+ identifierClosingStack.push(identifiers.get(letter).end)
const colors = colorIdentifier[letter].split(',')
const r = colors[0]
const g = colors[1]
const b = colors[2]
colorStack.push([r,g,b])
+ if (keepChar) {
+ currentSelector.innerHTML = letter
+ }
+
} else {
currentSelector.innerHTML = letter
}
- const r = colorStack[colorStack.length-1][0]
- const g = colorStack[colorStack.length-1][1]
- const b = colorStack[colorStack.length-1][2]
- const currentColor = `color: rgb(${r},${g},${b});`
- currentSelector.setAttribute('style', currentColor)
+ if (colorStack.length === 1) {
+ currentSelector.className = `test_${defaultColor}`
+ } else {
+ const r = colorStack[colorStack.length-1][0]
+ const g = colorStack[colorStack.length-1][1]
+ const b = colorStack[colorStack.length-1][2]
+ const currentColor = `color: rgb(${r},${g},${b});`
+ currentSelector.setAttribute('style', currentColor)
+ }
output.push(currentSelector)
}
return output