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
Stop Markdown list scans at HTML blocks
Emre Sokullu49cb2625ef7e
diff --git a/src/chrome/src/ui/markdown-render.js b/src/chrome/src/ui/markdown-render.jsindex 46997f85f..032f1d2da 100644--- a/src/chrome/src/ui/markdown-render.js+++ b/src/chrome/src/ui/markdown-render.js@@ -18,6 +18,7 @@ const LANGUAGE_ALIASES = Object.freeze({go: 'clike', rust: 'clike', rs: 'clike', swift: 'clike',php: 'clike', ruby: 'clike', rb: 'clike',});+const INTERRUPTING_HTML_BLOCK_TAGS = new Set(('address article aside base basefont blockquote body caption center col colgroup dd details dialog dir div dl dt fieldset figcaption figure footer form frame frameset h1 h2 h3 h4 h5 h6 head header hr html iframe legend li link main menu menuitem nav noframes ol optgroup option p param search section summary table tbody td tfoot th thead title tr track ul').split(' '));const JS_KEYWORDS = new Set(('abstract as async await break case catch class const continue debugger declare default delete do else enum export extends finally for from function get if implements import in infer instanceof interface keyof let namespace new of private protected public readonly return satisfies set static super switch throw try type typeof var void while with yield').split(' '));const JS_CONSTANTS = new Set(('true false null undefined NaN Infinity').split(' '));@@ -300,6 +301,13 @@ function outerFenceCloserAfterNested(return -1;}+function startsInterruptingHtmlBlock(content) {+ // CommonMark HTML block types 1–6 interrupt paragraphs; inline tags do not.+ if (/^(?:<!--|<\?|<![A-Za-z]|<!\[CDATA\[|<(?:pre|script|style|textarea)(?=[ \t>]|$))/i.test(content)) return true;+ const tag = content.match(/^<\/?([A-Za-z][A-Za-z0-9-]*)(?=[ \t>]|\/>|$)/);+ return Boolean(tag && INTERRUPTING_HTML_BLOCK_TAGS.has(tag[1].toLowerCase()));+}+function listContinuationContainer(source, position, prefix, indentation, noListScanPositions) {const current = fenceContainer(prefix, indentation);const continuationIndent = Math.max(@@ -383,6 +391,7 @@ function listContinuationContainer(source, position, prefix, indentation, noListconst thematicBreak = /^(?:(?:-[ \t]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})$/.test(content);const lazyParagraph = sameQuoteContainer && !lineIndent&& !thematicBreak+ && !startsInterruptingHtmlBlock(content)&& !/^(?:#{1,6}(?:\s|$)|(?:[-+*]|1[.)])[ \t]+\S|>|`{3,}|~{3,})/.test(content);if (lazyParagraph) {if (!lineStart) break;diff --git a/src/firefox/src/ui/markdown-render.js b/src/firefox/src/ui/markdown-render.jsindex 46997f85f..032f1d2da 100644--- a/src/firefox/src/ui/markdown-render.js+++ b/src/firefox/src/ui/markdown-render.js@@ -18,6 +18,7 @@ const LANGUAGE_ALIASES = Object.freeze({go: 'clike', rust: 'clike', rs: 'clike', swift: 'clike',php: 'clike', ruby: 'clike', rb: 'clike',});+const INTERRUPTING_HTML_BLOCK_TAGS = new Set(('address article aside base basefont blockquote body caption center col colgroup dd details dialog dir div dl dt fieldset figcaption figure footer form frame frameset h1 h2 h3 h4 h5 h6 head header hr html iframe legend li link main menu menuitem nav noframes ol optgroup option p param search section summary table tbody td tfoot th thead title tr track ul').split(' '));const JS_KEYWORDS = new Set(('abstract as async await break case catch class const continue debugger declare default delete do else enum export extends finally for from function get if implements import in infer instanceof interface keyof let namespace new of private protected public readonly return satisfies set static super switch throw try type typeof var void while with yield').split(' '));const JS_CONSTANTS = new Set(('true false null undefined NaN Infinity').split(' '));@@ -300,6 +301,13 @@ function outerFenceCloserAfterNested(return -1;}+function startsInterruptingHtmlBlock(content) {+ // CommonMark HTML block types 1–6 interrupt paragraphs; inline tags do not.+ if (/^(?:<!--|<\?|<![A-Za-z]|<!\[CDATA\[|<(?:pre|script|style|textarea)(?=[ \t>]|$))/i.test(content)) return true;+ const tag = content.match(/^<\/?([A-Za-z][A-Za-z0-9-]*)(?=[ \t>]|\/>|$)/);+ return Boolean(tag && INTERRUPTING_HTML_BLOCK_TAGS.has(tag[1].toLowerCase()));+}+function listContinuationContainer(source, position, prefix, indentation, noListScanPositions) {const current = fenceContainer(prefix, indentation);const continuationIndent = Math.max(@@ -383,6 +391,7 @@ function listContinuationContainer(source, position, prefix, indentation, noListconst thematicBreak = /^(?:(?:-[ \t]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})$/.test(content);const lazyParagraph = sameQuoteContainer && !lineIndent&& !thematicBreak+ && !startsInterruptingHtmlBlock(content)&& !/^(?:#{1,6}(?:\s|$)|(?:[-+*]|1[.)])[ \t]+\S|>|`{3,}|~{3,})/.test(content);if (lazyParagraph) {if (!lineStart) break;diff --git a/test/markdown-render.mjs b/test/markdown-render.mjsindex 751dacb99..28f46605c 100644--- a/test/markdown-render.mjs+++ b/test/markdown-render.mjs@@ -453,7 +453,7 @@ for (const build of ['chrome', 'firefox']) {}), '- item\n2. continuation\n BLOCK\nOutside');assert.deepEqual(lazyOrderedParagraphBlocks, [{ info: 'text', code: 'hi\n' }]);- for (const continuation of ['2.', '2. ', '1.', '1. ', '---text', '-_*']) {+ for (const continuation of ['2.', '2. ', '1.', '1. ', '---text', '-_*', '<span>inline</span>']) {const source = `- item\n${continuation}\n \`\`\`text\n hi\nOutside`;const blocks = [];assert.equal(helpers.replaceMarkdownCodeFences(source, (info, code) => {@@ -463,6 +463,16 @@ for (const build of ['chrome', 'firefox']) {assert.deepEqual(blocks, [{ info: 'text', code: 'hi\n' }]);}+ for (const interruptingHtml of ['<!-- done -->', '<?done?>', '<!DOCTYPE html>', '<![CDATA[x]]>', '<div>', '</div>']) {+ const source = `- item\n${interruptingHtml}\n \`\`\`text\n hi\nOutside`;+ const blocks = [];+ assert.equal(helpers.replaceMarkdownCodeFences(source, (info, code) => {+ blocks.push({ info, code });+ return 'BLOCK';+ }), `- item\n${interruptingHtml}\nBLOCK`);+ assert.deepEqual(blocks, [{ info: 'text', code: 'hi\nOutside' }]);+ }+for (const continuation of ['lazy continuation', '2. continuation', '2.', '---text']) {const source = `> - item\n> ${continuation}\n> \`\`\`text\n> hi\n> Outside`;const blocks = [];