Skip to content

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

Find indented Markdown fence continuations

Emre Sokullu245b2db6ddf1
diff --git a/src/chrome/src/ui/markdown-render.js b/src/chrome/src/ui/markdown-render.js
index 0a209a1a0..9893b9d0a 100644
--- a/src/chrome/src/ui/markdown-render.js
+++ b/src/chrome/src/ui/markdown-render.js
@@ -180,7 +180,9 @@ function listContinuationContainer(source, position, prefix, indentation) {
}
const lineIndent = indentationColumns(content.match(/^[ \t]*/)?.[0] || '');
- if (lineIndent < continuationIndent) break;
+ // A fenced continuation may be up to three columns deeper than ordinary
+ // list content, so continue back to the enclosing list marker first.
+ if (lineIndent < 2) break;
if (!lineStart) break;
lineEnd = lineStart - 1;
diff --git a/src/firefox/src/ui/markdown-render.js b/src/firefox/src/ui/markdown-render.js
index 0a209a1a0..9893b9d0a 100644
--- a/src/firefox/src/ui/markdown-render.js
+++ b/src/firefox/src/ui/markdown-render.js
@@ -180,7 +180,9 @@ function listContinuationContainer(source, position, prefix, indentation) {
}
const lineIndent = indentationColumns(content.match(/^[ \t]*/)?.[0] || '');
- if (lineIndent < continuationIndent) break;
+ // A fenced continuation may be up to three columns deeper than ordinary
+ // list content, so continue back to the enclosing list marker first.
+ if (lineIndent < 2) break;
if (!lineStart) break;
lineEnd = lineStart - 1;
diff --git a/test/markdown-render.mjs b/test/markdown-render.mjs
index 9742be9ab..d821e89f1 100644
--- a/test/markdown-render.mjs
+++ b/test/markdown-render.mjs
@@ -218,6 +218,14 @@ for (const build of ['chrome', 'firefox']) {
return 'BLOCK';
}), '- item\n BLOCK\nAfter');
assert.deepEqual(shortBlocks, [{ info: 'text', code: 'hello\n' }]);
+
+ const extraIndent = '10. item\n continuation\n ```js\n code\n ```';
+ const extraIndentBlocks = [];
+ assert.equal(helpers.replaceMarkdownCodeFences(extraIndent, (info, code) => {
+ extraIndentBlocks.push({ info, code });
+ return 'BLOCK';
+ }), '10. item\n continuation\n BLOCK');
+ assert.deepEqual(extraIndentBlocks, [{ info: 'js', code: ' code\n' }]);
});
test(`${build}: fences in nested list and quote containers preserve following content`, () => {