Skip to content

Commit

Permalink
Fixes, eternally
Browse files Browse the repository at this point in the history
  • Loading branch information
sabeechen committed Apr 15, 2024
1 parent 2cdf7b4 commit d0ab63d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/static/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion server/sw.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions ts/controls/chat-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class ChatMessage extends LitElement {
for (const block of latexBlocks) {
const latex = block.substring(8, block.length - 3);
const guid = uuidv4();
messageText = messageText.replace(block, guid);
messageText = messageText.replace(block, "`" + guid + "`");
latexMappingsBlocks[guid] = latex;
}
}
Expand All @@ -229,7 +229,7 @@ export class ChatMessage extends LitElement {
for (const block of latexBlocks2) {
const latex = block.substring(3, block.length - 3);
const guid = uuidv4();
messageText = messageText.replace(block, guid);
messageText = messageText.replace(block, "`" + guid + "`");
latexMappingsBlocks[guid] = latex;
}
}
Expand All @@ -251,12 +251,6 @@ export class ChatMessage extends LitElement {
messageHTML = document.createElement("div") as HTMLDivElement;
for (const child of children) {
messageHTML.appendChild(child);
const text = child.textContent;
if (latexMappingsBlocks[text])
{
child.innerHTML = "";
katex.render(latexMappingsBlocks[text], child as HTMLElement, {throwOnError: false, output: "mathml", displayMode: true});
}

// Search through the child nodes for any text nodes that contain the sentinal guids for inline latex and replace them with the rendered latex. Markdown shold have rendered the guids inside "code" elements.
for (const node of child.querySelectorAll("code")) {
Expand All @@ -268,6 +262,10 @@ export class ChatMessage extends LitElement {
katex.render(latex, newNode, {throwOnError: false, output: "mathml", displayMode: false});
node.parentElement.replaceChild(newNode, node);
}
else if(latexMappingsBlocks[text])
{
katex.render(latexMappingsBlocks[text], node, {throwOnError: false, output: "mathml", displayMode: true});
}
}
}

Expand Down

0 comments on commit d0ab63d

Please sign in to comment.