Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Preserve indented Markdown list snippets

Emre Sokullu6aea83bd5883
diff --git a/src/chrome/src/ui/markdown-render.js b/src/chrome/src/ui/markdown-render.js
index 80ceba667..04e240ccf 100644
--- a/src/chrome/src/ui/markdown-render.js
+++ b/src/chrome/src/ui/markdown-render.js
@@ -72,7 +72,7 @@ function fenceContainer(prefix, indentation = '') {
remainder = remainder.slice(quote[0].length);
continue;
}
- const list = remainder.match(/^[ \t]*(?:[-+*]|\d+[.)])[ \t]+/);
+ const list = remainder.match(/^[ \t]*(?:[-+*]|\d+[.)])[ \t]/);
if (!list) break;
const listStartColumn = indentationColumns(source.slice(0, source.length - remainder.length));
listPrefix += list[0];
@@ -259,6 +259,10 @@ function listContinuationContainer(source, position, prefix, indentation, noList
if (source[lineEnd] === '\r') lineEnd -= 1;
continue;
}
+ const precedingFence = parseFenceLine(line);
+ if (precedingFence && fenceIndentationColumns(fenceContainer(precedingFence.prefix, precedingFence.indentation)) > 3) {
+ return noList();
+ }
const precedingContainer = fenceContainer(line);
const missingQuotes = current.quoteDepth - precedingContainer.quoteDepth;
if (missingQuotes < 0 || (missingQuotes && !current.leadingQuoteIndent)) return noList();
@@ -366,7 +370,7 @@ function parseFenceLine(line) {
offset += quote[0].length;
continue;
}
- const list = segment.match(/^[ \t]*(?:[-+*]|\d+[.)])[ \t]+/);
+ const list = segment.match(/^[ \t]*(?:[-+*]|\d+[.)])[ \t]/);
if (!list) break;
offset += list[0].length;
}
diff --git a/src/chrome/src/ui/skill-markdown.js b/src/chrome/src/ui/skill-markdown.js
index d5c3c93c8..2dd0f4ac6 100644
--- a/src/chrome/src/ui/skill-markdown.js
+++ b/src/chrome/src/ui/skill-markdown.js
@@ -42,7 +42,7 @@ export function renderSkillMarkdown(content) {
const placeholder = `__SKILL_CODE_BLOCK_${codeBlocks.length}__`;
codeBlocks.push(code);
return placeholder;
- }, { streaming: true });
+ });
const inlineCodes = [];
text = text.replace(/`([^`\n]+)`/g, (_match, code) => {
const placeholder = `__SKILL_INLINE_CODE_${inlineCodes.length}__`;
diff --git a/src/firefox/src/ui/markdown-render.js b/src/firefox/src/ui/markdown-render.js
index 80ceba667..04e240ccf 100644
--- a/src/firefox/src/ui/markdown-render.js
+++ b/src/firefox/src/ui/markdown-render.js
@@ -72,7 +72,7 @@ function fenceContainer(prefix, indentation = '') {
remainder = remainder.slice(quote[0].length);
continue;
}
- const list = remainder.match(/^[ \t]*(?:[-+*]|\d+[.)])[ \t]+/);
+ const list = remainder.match(/^[ \t]*(?:[-+*]|\d+[.)])[ \t]/);
if (!list) break;
const listStartColumn = indentationColumns(source.slice(0, source.length - remainder.length));
listPrefix += list[0];
@@ -259,6 +259,10 @@ function listContinuationContainer(source, position, prefix, indentation, noList
if (source[lineEnd] === '\r') lineEnd -= 1;
continue;
}
+ const precedingFence = parseFenceLine(line);
+ if (precedingFence && fenceIndentationColumns(fenceContainer(precedingFence.prefix, precedingFence.indentation)) > 3) {
+ return noList();
+ }
const precedingContainer = fenceContainer(line);
const missingQuotes = current.quoteDepth - precedingContainer.quoteDepth;
if (missingQuotes < 0 || (missingQuotes && !current.leadingQuoteIndent)) return noList();
@@ -366,7 +370,7 @@ function parseFenceLine(line) {
offset += quote[0].length;
continue;
}
- const list = segment.match(/^[ \t]*(?:[-+*]|\d+[.)])[ \t]+/);
+ const list = segment.match(/^[ \t]*(?:[-+*]|\d+[.)])[ \t]/);
if (!list) break;
offset += list[0].length;
}
diff --git a/src/firefox/src/ui/skill-markdown.js b/src/firefox/src/ui/skill-markdown.js
index d5c3c93c8..2dd0f4ac6 100644
--- a/src/firefox/src/ui/skill-markdown.js
+++ b/src/firefox/src/ui/skill-markdown.js
@@ -42,7 +42,7 @@ export function renderSkillMarkdown(content) {
const placeholder = `__SKILL_CODE_BLOCK_${codeBlocks.length}__`;
codeBlocks.push(code);
return placeholder;
- }, { streaming: true });
+ });
const inlineCodes = [];
text = text.replace(/`([^`\n]+)`/g, (_match, code) => {
const placeholder = `__SKILL_INLINE_CODE_${inlineCodes.length}__`;
diff --git a/test/markdown-render.mjs b/test/markdown-render.mjs
index ab7ba0c7e..77b45f7a1 100644
--- a/test/markdown-render.mjs
+++ b/test/markdown-render.mjs
@@ -44,7 +44,6 @@ for (const build of ['chrome', 'firefox']) {
assert.match(html, /<h2>Next steps<\/h2>Review it\./);
assert.doesNotMatch(html, /<script>|<h[1-6]>Role|<br>text<br>|<br>bash<br>/i);
}
- assert.deepEqual(preContents(renderSkillMarkdown(source)), [escapeHtml(readme)]);
}
});
@@ -57,6 +56,10 @@ for (const build of ['chrome', 'firefox']) {
]);
assert.match(html, /Visible prose/);
assert.match(html, /After/);
+ assert.deepEqual(preContents(renderSkillMarkdown(source)), [
+ escapeHtml('```js\nliteral\n'),
+ escapeHtml('independent\n'),
+ ]);
});
test(`${build}: Markdown wrappers retain longer nested fences`, () => {
@@ -64,7 +67,6 @@ for (const build of ['chrome', 'firefox']) {
const source = `\`\`\`markdown\n${nested}\n\`\`\`\n\n## Outside`;
assert.deepEqual(preContents(formatMarkdown(source, { recoverNestedMarkdown: true })), [helpers.escapeCodeHtml(`${nested}\n`)]);
assert.match(formatMarkdown(source, { recoverNestedMarkdown: true }), /<h2>Outside<\/h2>/);
- assert.deepEqual(preContents(renderSkillMarkdown(source)), [escapeHtml(`${nested}\n`)]);
});
test(`${build}: Markdown wrappers retain list-prefixed nested fences`, () => {
@@ -72,7 +74,6 @@ for (const build of ['chrome', 'firefox']) {
const source = `\`\`\`markdown\n${nested}\`\`\`\nOutside`;
assert.deepEqual(preContents(formatMarkdown(source, { recoverNestedMarkdown: true })), [helpers.escapeCodeHtml(nested)]);
assert.match(formatMarkdown(source, { recoverNestedMarkdown: true }), /Outside/);
- assert.deepEqual(preContents(renderSkillMarkdown(source)), [escapeHtml(nested)]);
});
test(`${build}: Markdown wrappers keep over-indented fences literal`, () => {
@@ -80,7 +81,6 @@ for (const build of ['chrome', 'firefox']) {
const source = `\`\`\`markdown\n${nested}\`\`\`\nAfter`;
assert.deepEqual(preContents(formatMarkdown(source, { recoverNestedMarkdown: true })), [helpers.escapeCodeHtml(nested)]);
assert.match(formatMarkdown(source, { recoverNestedMarkdown: true }), /After/);
- assert.deepEqual(preContents(renderSkillMarkdown(source)), [escapeHtml(nested)]);
});
test(`${build}: Markdown wrappers retain alternate nested fence markers`, () => {
@@ -88,7 +88,6 @@ for (const build of ['chrome', 'firefox']) {
const source = `\`\`\`markdown\n${nested}\`\`\`\nAfter`;
assert.deepEqual(preContents(formatMarkdown(source, { recoverNestedMarkdown: true })), [helpers.escapeCodeHtml(nested)]);
assert.match(formatMarkdown(source, { recoverNestedMarkdown: true }), /After/);
- assert.deepEqual(preContents(renderSkillMarkdown(source)), [escapeHtml(nested)]);
});
test(`${build}: Markdown wrappers retain distant alternate fence closers`, () => {
@@ -96,7 +95,6 @@ for (const build of ['chrome', 'firefox']) {
const source = `\`\`\`markdown\n${nested}\`\`\`\nAfter`;
assert.deepEqual(preContents(formatMarkdown(source, { recoverNestedMarkdown: true })), [helpers.escapeCodeHtml(nested)]);
assert.match(formatMarkdown(source, { recoverNestedMarkdown: true }), /After/);
- assert.deepEqual(preContents(renderSkillMarkdown(source)), [escapeHtml(nested)]);
});
test(`${build}: Markdown wrappers leave unmatched nested fences literal`, () => {
@@ -104,7 +102,6 @@ for (const build of ['chrome', 'firefox']) {
const source = `\`\`\`\`markdown\n${nested}\`\`\`\`\nAfter`;
assert.deepEqual(preContents(formatMarkdown(source, { recoverNestedMarkdown: true })), [helpers.escapeCodeHtml(nested)]);
assert.match(formatMarkdown(source, { recoverNestedMarkdown: true }), /After/);
- assert.deepEqual(preContents(renderSkillMarkdown(source)), [escapeHtml(nested)]);
});
test(`${build}: fence length, marker and whole-line closers protect literal code`, () => {
@@ -138,6 +135,9 @@ for (const build of ['chrome', 'firefox']) {
return 'BLOCK';
}), 'BLOCK\nAfter');
assert.deepEqual(blocks, [{ info: 'text', code: 'hello\n' }]);
+
+ const excessListPadding = '- ```text\n literal\n ```\nAfter';
+ assert.equal(helpers.replaceMarkdownCodeFences(excessListPadding, () => 'BLOCK'), excessListPadding);
});
test(`${build}: container-prefixed markers do not close an outer fenced block`, () => {
@@ -175,7 +175,6 @@ for (const build of ['chrome', 'firefox']) {
const source = `\`\`\`markdown\n${content}`;
const html = formatMarkdown(source, { enhance: false, recoverNestedMarkdown: true });
assert.deepEqual(preContents(html), [escapeHtml(content)]);
- assert.deepEqual(preContents(renderSkillMarkdown(source)), [escapeHtml(content)]);
assert.doesNotMatch(html, /<h[1-6]>|<img |code-copy-btn/);
}
const quoted = '> ```text\n> hello\n';