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
Parse nested Markdown list containers
Emre Sokullu80d11f953803
diff --git a/src/chrome/src/ui/markdown-render.js b/src/chrome/src/ui/markdown-render.jsindex e8480e7b7..80ceba667 100644--- a/src/chrome/src/ui/markdown-render.js+++ b/src/chrome/src/ui/markdown-render.js@@ -142,6 +142,7 @@ function stripContainerPrefix(line, container) {const listIndent = container.listIndentGroups[quoteIndex];remainder = consumeIndentationColumns(remainder, listIndent, column);if (remainder == null) return null;+ column += listIndent;const quote = remainder.match(/^ {0,3}>[ \t]?/);if (!quote) return null;column = indentationColumnsAt(quote[0], column);@@ -258,15 +259,14 @@ function listContinuationContainer(source, position, prefix, indentation, noListif (source[lineEnd] === '\r') lineEnd -= 1;continue;}- const quotePrefix = line.match(/^(?:[ \t]*>[ \t]?)+/)?.[0] || '';- const quoteDepth = (quotePrefix.match(/>/g) || []).length;- const missingQuotes = current.quoteDepth - quoteDepth;+ const precedingContainer = fenceContainer(line);+ const missingQuotes = current.quoteDepth - precedingContainer.quoteDepth;if (missingQuotes < 0 || (missingQuotes && !current.leadingQuoteIndent)) return noList();- const content = line.slice(quotePrefix.length);- const listPrefix = content.match(/^(?:[ \t]*(?:[-+*]|\d+[.)])[ \t]+)+/)?.[0] || '';- if (listPrefix) {- const container = fenceContainer(`${quotePrefix}${listPrefix}${'> '.repeat(missingQuotes)}`);+ if (precedingContainer.listPrefix) {+ const container = missingQuotes+ ? fenceContainer(`${precedingContainer.rawPrefix}${'> '.repeat(missingQuotes)}`)+ : precedingContainer;const listIndent = container.listIndentGroups.at(-1);if (listIndent && continuationIndent >= listIndent && continuationIndent <= listIndent + 3) {return container;@@ -274,6 +274,8 @@ function listContinuationContainer(source, position, prefix, indentation, noListreturn noList();}+ const quotePrefix = line.match(/^(?:[ \t]*>[ \t]?)+/)?.[0] || '';+ const content = line.slice(quotePrefix.length);const lineIndentation = content.match(/^[ \t]*/)?.[0] || '';const lineStartColumn = indentationColumns(quotePrefix);const lineIndent = indentationColumnsAt(lineIndentation, lineStartColumn) - lineStartColumn;diff --git a/src/firefox/src/ui/markdown-render.js b/src/firefox/src/ui/markdown-render.jsindex e8480e7b7..80ceba667 100644--- a/src/firefox/src/ui/markdown-render.js+++ b/src/firefox/src/ui/markdown-render.js@@ -142,6 +142,7 @@ function stripContainerPrefix(line, container) {const listIndent = container.listIndentGroups[quoteIndex];remainder = consumeIndentationColumns(remainder, listIndent, column);if (remainder == null) return null;+ column += listIndent;const quote = remainder.match(/^ {0,3}>[ \t]?/);if (!quote) return null;column = indentationColumnsAt(quote[0], column);@@ -258,15 +259,14 @@ function listContinuationContainer(source, position, prefix, indentation, noListif (source[lineEnd] === '\r') lineEnd -= 1;continue;}- const quotePrefix = line.match(/^(?:[ \t]*>[ \t]?)+/)?.[0] || '';- const quoteDepth = (quotePrefix.match(/>/g) || []).length;- const missingQuotes = current.quoteDepth - quoteDepth;+ const precedingContainer = fenceContainer(line);+ const missingQuotes = current.quoteDepth - precedingContainer.quoteDepth;if (missingQuotes < 0 || (missingQuotes && !current.leadingQuoteIndent)) return noList();- const content = line.slice(quotePrefix.length);- const listPrefix = content.match(/^(?:[ \t]*(?:[-+*]|\d+[.)])[ \t]+)+/)?.[0] || '';- if (listPrefix) {- const container = fenceContainer(`${quotePrefix}${listPrefix}${'> '.repeat(missingQuotes)}`);+ if (precedingContainer.listPrefix) {+ const container = missingQuotes+ ? fenceContainer(`${precedingContainer.rawPrefix}${'> '.repeat(missingQuotes)}`)+ : precedingContainer;const listIndent = container.listIndentGroups.at(-1);if (listIndent && continuationIndent >= listIndent && continuationIndent <= listIndent + 3) {return container;@@ -274,6 +274,8 @@ function listContinuationContainer(source, position, prefix, indentation, noListreturn noList();}+ const quotePrefix = line.match(/^(?:[ \t]*>[ \t]?)+/)?.[0] || '';+ const content = line.slice(quotePrefix.length);const lineIndentation = content.match(/^[ \t]*/)?.[0] || '';const lineStartColumn = indentationColumns(quotePrefix);const lineIndent = indentationColumnsAt(lineIndentation, lineStartColumn) - lineStartColumn;diff --git a/test/markdown-render.mjs b/test/markdown-render.mjsindex 271fe0c07..ab7ba0c7e 100644--- a/test/markdown-render.mjs+++ b/test/markdown-render.mjs@@ -269,6 +269,7 @@ for (const build of ['chrome', 'firefox']) {['10. Step\n ```js\n const value = true;\n ```\nAfter', '10. Step\n BLOCK\nAfter'],['10. Step\n continuation\n ```js\n const value = true;\n ```\nAfter', '10. Step\n continuation\n BLOCK\nAfter'],['> 10. Step\n> ```js\n> const value = true;\n> ```\n> After', '> 10. Step\n> BLOCK\n> After'],+ ['- > - item\n > ```js\n > const value = true;\n > ```\nAfter', '- > - item\n > BLOCK\nAfter'],];for (const [source, expected] of cases) {const blocks = [];@@ -482,6 +483,14 @@ for (const build of ['chrome', 'firefox']) {return 'BLOCK';}), '> BLOCK');assert.deepEqual(quotedTabBlocks, [{ info: 'text', code: 'hello\n' }]);++ const nestedQuotedList = '- > -\t```text\n > \thello\n > \t```\nAfter';+ const nestedQuotedListBlocks = [];+ assert.equal(helpers.replaceMarkdownCodeFences(nestedQuotedList, (info, code) => {+ nestedQuotedListBlocks.push({ info, code });+ return 'BLOCK';+ }), '- > -\tBLOCK\nAfter');+ assert.deepEqual(nestedQuotedListBlocks, [{ info: 'text', code: 'hello\n' }]);});test(`${build}: saved history uses an outer fence longer than all literal backticks`, () => {