Skip to content

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

Scan quoted Markdown list continuations

Emre Sokulluab3ac294eada
diff --git a/src/chrome/src/ui/markdown-render.js b/src/chrome/src/ui/markdown-render.js
index f5d77e050..3ff171fc9 100644
--- a/src/chrome/src/ui/markdown-render.js
+++ b/src/chrome/src/ui/markdown-render.js
@@ -344,11 +344,15 @@ function listContinuationContainer(source, position, prefix, indentation, noList
const missingQuotes = current.quoteDepth - precedingContainer.quoteDepth;
if (missingQuotes < 0 || (missingQuotes && !current.leadingQuoteIndent)) return noList();
+ const quotePrefix = quotePrefixAt(line);
+ const content = line.slice(quotePrefix.length);
+ const sameQuoteContainer = precedingContainer.quoteDepth === current.quoteDepth
+ && (!current.quoteDepth || Boolean(quotePrefix));
const followsNonblankLine = lineStart > 0
&& Boolean(source.slice(source.lastIndexOf('\n', lineStart - 2) + 1, lineStart - 1).trim());
- const nonInterruptingOrderedMarker = followsNonblankLine && !current.quoteDepth
- && (/^[ \t]*\d{1,9}[.)][ \t]*$/.test(line)
- || (/^[ \t]*\d{1,9}[.)][ \t]/.test(line) && !/^[ \t]*1[.)][ \t]/.test(line)));
+ const nonInterruptingOrderedMarker = followsNonblankLine && sameQuoteContainer
+ && (/^[ \t]*\d{1,9}[.)][ \t]*$/.test(content)
+ || (/^[ \t]*\d{1,9}[.)][ \t]/.test(content) && !/^[ \t]*1[.)][ \t]/.test(content)));
if (precedingContainer.listPrefix && !nonInterruptingOrderedMarker) {
let container = missingQuotes
? fenceContainer(`${precedingContainer.containerPrefix}${'> '.repeat(missingQuotes)}`)
@@ -370,8 +374,6 @@ function listContinuationContainer(source, position, prefix, indentation, noList
return noList();
}
- const quotePrefix = quotePrefixAt(line);
- const content = line.slice(quotePrefix.length);
const lineIndentation = content.match(/^[ \t]*/)?.[0] || '';
const lineStartColumn = indentationColumns(quotePrefix);
const lineIndent = indentationColumnsAt(lineIndentation, lineStartColumn) - lineStartColumn;
@@ -379,7 +381,7 @@ function listContinuationContainer(source, position, prefix, indentation, noList
// list content, so continue back to the enclosing list marker first.
if (lineIndent < 2) {
const thematicBreak = /^(?:(?:-[ \t]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})$/.test(content);
- const lazyParagraph = !quotePrefix && !lineIndent && !current.quoteDepth
+ const lazyParagraph = sameQuoteContainer && !lineIndent
&& !thematicBreak
&& !/^(?:#{1,6}(?:\s|$)|(?:[-+*]|1[.)])[ \t]+\S|>|`{3,}|~{3,})/.test(content);
if (lazyParagraph) {
diff --git a/src/firefox/src/ui/markdown-render.js b/src/firefox/src/ui/markdown-render.js
index f5d77e050..3ff171fc9 100644
--- a/src/firefox/src/ui/markdown-render.js
+++ b/src/firefox/src/ui/markdown-render.js
@@ -344,11 +344,15 @@ function listContinuationContainer(source, position, prefix, indentation, noList
const missingQuotes = current.quoteDepth - precedingContainer.quoteDepth;
if (missingQuotes < 0 || (missingQuotes && !current.leadingQuoteIndent)) return noList();
+ const quotePrefix = quotePrefixAt(line);
+ const content = line.slice(quotePrefix.length);
+ const sameQuoteContainer = precedingContainer.quoteDepth === current.quoteDepth
+ && (!current.quoteDepth || Boolean(quotePrefix));
const followsNonblankLine = lineStart > 0
&& Boolean(source.slice(source.lastIndexOf('\n', lineStart - 2) + 1, lineStart - 1).trim());
- const nonInterruptingOrderedMarker = followsNonblankLine && !current.quoteDepth
- && (/^[ \t]*\d{1,9}[.)][ \t]*$/.test(line)
- || (/^[ \t]*\d{1,9}[.)][ \t]/.test(line) && !/^[ \t]*1[.)][ \t]/.test(line)));
+ const nonInterruptingOrderedMarker = followsNonblankLine && sameQuoteContainer
+ && (/^[ \t]*\d{1,9}[.)][ \t]*$/.test(content)
+ || (/^[ \t]*\d{1,9}[.)][ \t]/.test(content) && !/^[ \t]*1[.)][ \t]/.test(content)));
if (precedingContainer.listPrefix && !nonInterruptingOrderedMarker) {
let container = missingQuotes
? fenceContainer(`${precedingContainer.containerPrefix}${'> '.repeat(missingQuotes)}`)
@@ -370,8 +374,6 @@ function listContinuationContainer(source, position, prefix, indentation, noList
return noList();
}
- const quotePrefix = quotePrefixAt(line);
- const content = line.slice(quotePrefix.length);
const lineIndentation = content.match(/^[ \t]*/)?.[0] || '';
const lineStartColumn = indentationColumns(quotePrefix);
const lineIndent = indentationColumnsAt(lineIndentation, lineStartColumn) - lineStartColumn;
@@ -379,7 +381,7 @@ function listContinuationContainer(source, position, prefix, indentation, noList
// list content, so continue back to the enclosing list marker first.
if (lineIndent < 2) {
const thematicBreak = /^(?:(?:-[ \t]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})$/.test(content);
- const lazyParagraph = !quotePrefix && !lineIndent && !current.quoteDepth
+ const lazyParagraph = sameQuoteContainer && !lineIndent
&& !thematicBreak
&& !/^(?:#{1,6}(?:\s|$)|(?:[-+*]|1[.)])[ \t]+\S|>|`{3,}|~{3,})/.test(content);
if (lazyParagraph) {
diff --git a/test/markdown-render.mjs b/test/markdown-render.mjs
index e36bcd794..32c3fe2ea 100644
--- a/test/markdown-render.mjs
+++ b/test/markdown-render.mjs
@@ -455,6 +455,16 @@ for (const build of ['chrome', 'firefox']) {
assert.deepEqual(blocks, [{ info: 'text', code: 'hi\n' }]);
}
+ for (const continuation of ['lazy continuation', '2. continuation', '2.', '---text']) {
+ const source = `> - item\n> ${continuation}\n> \`\`\`text\n> hi\n> Outside`;
+ const blocks = [];
+ assert.equal(helpers.replaceMarkdownCodeFences(source, (info, code) => {
+ blocks.push({ info, code });
+ return 'BLOCK';
+ }), `> - item\n> ${continuation}\n> BLOCK\n> Outside`);
+ assert.deepEqual(blocks, [{ info: 'text', code: 'hi\n' }]);
+ }
+
const noCloser = '> ```text\n> inside\nOutside';
const noCloserBlocks = [];
assert.equal(helpers.replaceMarkdownCodeFences(noCloser, (info, code) => {