ai: turn inline latex into latex code blocks for proper rendering

it looks poopy sometimes but still better than copilot failing all the time
This commit is contained in:
end-4
2025-04-03 23:19:13 +02:00
parent ac59f23ca4
commit 5591e59680
2 changed files with 22 additions and 5 deletions
@@ -6,7 +6,7 @@ import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
const { Box, Button, Label, Icon, Scrollable, Stack } = Widget;
const { execAsync, exec } = Utils;
import { MaterialIcon } from '../../.commonwidgets/materialicon.js';
import md2pango from '../../.miscutils/md2pango.js';
import md2pango, { replaceInlineLatexWithCodeBlocks } from '../../.miscutils/md2pango.js';
import { darkMode } from "../../.miscutils/system.js";
const LATEX_DIR = `${GLib.get_user_cache_dir()}/ags/media/latex`;
@@ -216,12 +216,11 @@ const MessageContent = (content) => {
child.destroy();
}
contentBox.add(TextBlock())
// Loop lines. Put normal text in markdown parser
// and put code into code highlighter (TODO)
let lines = content.split('\n');
let lines = replaceInlineLatexWithCodeBlocks(content).split('\n');
let lastProcessed = 0;
let inCode = false;
for (const [index, line] of lines.entries()) {
for (let [index, line] of lines.entries()) {
// Code blocks
const codeBlockRegex = /^\s*```([a-zA-Z0-9]+)?\n?/;
if (codeBlockRegex.test(line)) {