Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Separate history fence info strings
Emre Sokullu63a781306449
diff --git a/src/chrome/src/ui/history-text.js b/src/chrome/src/ui/history-text.jsindex 568768ffa..c72b3b6d6 100644--- a/src/chrome/src/ui/history-text.js+++ b/src/chrome/src/ui/history-text.js@@ -138,7 +138,10 @@ export function historyTextFromElement(root, { markdown = true } = {}) {fenceLength = Math.max(fenceLength, match[0].length + 1);}const fence = fenceCharacter.repeat(fenceLength);- output = `${beforeCode}${fence}${language}\n${code}${fence}`;+ // Keep an info string separate from the fence so a label beginning with+ // the same marker cannot extend the opener past its matching closer.+ const info = language ? ` ${language}` : '';+ output = `${beforeCode}${fence}${info}\n${code}${fence}`;return;}if (markdown && tagName === 'CODE' && !inPre) {diff --git a/src/firefox/src/ui/history-text.js b/src/firefox/src/ui/history-text.jsindex 568768ffa..c72b3b6d6 100644--- a/src/firefox/src/ui/history-text.js+++ b/src/firefox/src/ui/history-text.js@@ -138,7 +138,10 @@ export function historyTextFromElement(root, { markdown = true } = {}) {fenceLength = Math.max(fenceLength, match[0].length + 1);}const fence = fenceCharacter.repeat(fenceLength);- output = `${beforeCode}${fence}${language}\n${code}${fence}`;+ // Keep an info string separate from the fence so a label beginning with+ // the same marker cannot extend the opener past its matching closer.+ const info = language ? ` ${language}` : '';+ output = `${beforeCode}${fence}${info}\n${code}${fence}`;return;}if (markdown && tagName === 'CODE' && !inPre) {diff --git a/test/markdown-render.mjs b/test/markdown-render.mjsindex a1badfda8..2b8524194 100644--- a/test/markdown-render.mjs+++ b/test/markdown-render.mjs@@ -187,7 +187,7 @@ for (const build of ['chrome', 'firefox']) {const pre = element('PRE', element('CODE', text(code)));pre.parentElement = { querySelector: () => ({ textContent: 'markdown' }) };const saved = historyTextFromElement(element('DIV', pre));- const firstFence = saved.match(/^(`+)markdown/)[1];+ const firstFence = saved.match(/^(`+) markdown/)[1];assert.ok([...code.matchAll(/`+/g)].every(match => match[0].length < firstFence.length));assert.deepEqual(preContents(renderSkillMarkdown(saved)), [escapeHtml(code)]);assert.deepEqual(preContents(formatMarkdown(saved)), [helpers.escapeCodeHtml(code)]);@@ -201,7 +201,20 @@ for (const build of ['chrome', 'firefox']) {const pre = element('PRE', element('CODE', text(code)));pre.parentElement = { querySelector: () => ({ textContent: '`javascript`' }) };const saved = historyTextFromElement(element('DIV', pre));- assert.match(saved, /^~~~~`javascript`\n~~~\nconst value = true;\n~~~~$/);+ assert.match(saved, /^~~~~ `javascript`\n~~~\nconst value = true;\n~~~~$/);+ const source = `${saved}\n## After`;+ assert.deepEqual(preContents(formatMarkdown(source)), [helpers.escapeCodeHtml(code)]);+ assert.match(formatMarkdown(source), /<h2>After<\/h2>/);+ });++ test(`${build}: history keeps tilde-prefixed labels separate from the fence`, () => {+ const text = value => ({ nodeType: 3, nodeValue: value });+ const element = (tagName, ...childNodes) => ({ nodeType: 1, tagName, childNodes });+ const code = 'const value = true;\n';+ const pre = element('PRE', element('CODE', text(code)));+ pre.parentElement = { querySelector: () => ({ textContent: '~lang`x' }) };+ const saved = historyTextFromElement(element('DIV', pre));+ assert.match(saved, /^~~~ ~lang`x\nconst value = true;\n~~~$/);const source = `${saved}\n## After`;assert.deepEqual(preContents(formatMarkdown(source)), [helpers.escapeCodeHtml(code)]);assert.match(formatMarkdown(source), /<h2>After<\/h2>/);