Skip to content

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

Render lists and --- rules in side panel answers

Emre Sokullu1638d42b2529
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d9a8c5645..eced89bb2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,9 @@ This changelog was generated from the repository Git history and release tags. V
## [Unreleased]
+### Fixed
+- Side panel answers show bullet and numbered lists, nested by indentation, and `---` rules as lists and dividers instead of literal `*`, `-` and `---` lines. Each list item gets its own emphasis, so a `*` bullet no longer pairs with an asterisk in another item, and saved history keeps the lists as Markdown that renders the same way. Both builds.
+
## [45.0.2] - 2026-10-29
### Added
diff --git a/src/chrome/src/ui/history-text.js b/src/chrome/src/ui/history-text.js
index dc19024a6..10d43b92d 100644
--- a/src/chrome/src/ui/history-text.js
+++ b/src/chrome/src/ui/history-text.js
@@ -134,9 +134,11 @@ export function historyTextFromElement(root, { markdown = true } = {}) {
return;
}
if (tagName === 'HR') {
+ // Blank lines around it keep a saved rule from reading as the underline
+ // of a heading on the line above.
ensureBreak();
- output += '---';
- appendHardBreak();
+ if (output && !output.endsWith('\n\n')) output += '\n';
+ output += '---\n\n';
return;
}
@@ -194,6 +196,28 @@ export function historyTextFromElement(root, { markdown = true } = {}) {
if (href) output += `](${href})`;
return;
}
+ if (markdown && (tagName === 'UL' || tagName === 'OL')) {
+ // A rendered list goes back to Markdown the panel renders as one: a
+ // marker per item, and its further lines and nested lists indented
+ // under the marker.
+ const ordered = tagName === 'OL';
+ let number = Number.parseInt(String(node.getAttribute?.('start') ?? '1'), 10);
+ if (!Number.isSafeInteger(number) || number < 0) number = 1;
+ const items = [];
+ for (const item of elementChildren(node)) {
+ if (String(item.tagName || '').toUpperCase() !== 'LI') continue;
+ const marker = ordered ? `${number++}. ` : '- ';
+ const body = historyTextFromElement(item, { markdown: true }).replace(/^\n+|\s+$/g, '');
+ items.push(marker + body.split('\n')
+ .map((line, index) => (index && line ? ' '.repeat(marker.length) + line : line)).join('\n'));
+ }
+ if (items.length) {
+ ensureBreak();
+ output += items.join('\n');
+ ensureBreak();
+ }
+ return;
+ }
if (markdown && (tagName === 'TABLE' || node.classList?.contains?.('markdown-table-wrapper'))) {
const markdownTable = markdownTableFromElement(tableElementFromNode(node) || node);
if (markdownTable) {
diff --git a/src/chrome/src/ui/markdown-render.js b/src/chrome/src/ui/markdown-render.js
index 21f529681..b337cc476 100644
--- a/src/chrome/src/ui/markdown-render.js
+++ b/src/chrome/src/ui/markdown-render.js
@@ -850,6 +850,115 @@ export function highlightCode(code, language) {
}
}
+// A thematic break: three or more -, * or _ alone on a line ("---", "* * *").
+const MARKDOWN_RULE = /^[ \t]{0,3}([-*_])(?:[ \t]*\1){2,}[ \t]*$/;
+// A bullet (-, * or +) or numbered (1. or 1)) list item with its text.
+const MARKDOWN_LIST_ITEM = /^([ \t]*)([-*+]|\d{1,9}[.)])[ \t]+(\S.*)$/;
+
+function markdownIndent(line) {
+ let width = 0;
+ for (const character of /^[ \t]*/.exec(line)[0]) width += character === '\t' ? 4 - (width % 4) : 1;
+ return width;
+}
+
+function markdownListItem(line) {
+ const match = MARKDOWN_LIST_ITEM.exec(line);
+ if (!match || MARKDOWN_RULE.test(line)) return null;
+ const ordered = /\d/.test(match[2]);
+ return {
+ indent: markdownIndent(line),
+ tag: ordered ? 'ol' : 'ul',
+ number: ordered ? Number.parseInt(match[2], 10) : 1,
+ text: match[3],
+ };
+}
+
+// One list block from lines[start]: nested by indentation, items continued by
+// indented lines, kept open across blank lines that more of it follows.
+function parseMarkdownList(lines, start) {
+ const roots = [];
+ const open = [];
+ const openList = (item, owner) => {
+ const list = { tag: item.tag, start: item.number, indent: item.indent, items: [] };
+ (owner ? owner.lists : roots).push(list);
+ open.push(list);
+ return list;
+ };
+ let index = start;
+ while (index < lines.length) {
+ const line = lines[index];
+ if (!line.trim()) {
+ let next = index + 1;
+ while (next < lines.length && !lines[next].trim()) next += 1;
+ const following = lines[next];
+ if (following === undefined || MARKDOWN_RULE.test(following)
+ || (!markdownListItem(following) && markdownIndent(following) === 0)) break;
+ index = next;
+ continue;
+ }
+ if (MARKDOWN_RULE.test(line)) break;
+ const item = markdownListItem(line);
+ if (item) {
+ while (open.length && open[open.length - 1].indent > item.indent) open.pop();
+ let list = open[open.length - 1];
+ if (!list) list = openList(item, null);
+ else if (item.indent > list.indent) list = openList(item, list.items[list.items.length - 1]);
+ else if (list.tag !== item.tag) {
+ open.pop();
+ const parent = open[open.length - 1];
+ list = openList(item, parent ? parent.items[parent.items.length - 1] : null);
+ }
+ list.items.push({ lines: [item.text], lists: [] });
+ index += 1;
+ continue;
+ }
+ // Indented text continues the innermost item; unindented text ends the list.
+ if (!open.length || markdownIndent(line) === 0) break;
+ const list = open[open.length - 1];
+ list.items[list.items.length - 1].lines.push(line.trim());
+ index += 1;
+ }
+ return { roots, next: index };
+}
+
+/**
+ * Convert escaped Markdown bullet and numbered lists (nested by indentation)
+ * and thematic breaks (---) into <ul>/<ol> and <hr>. renderItem formats one
+ * item's text, whose lines it receives joined by \n; wrap receives each
+ * finished block and returns what stands for it in the text, so a caller can
+ * keep later passes out of it. A block keeps its own line: blank lines around
+ * a rule are dropped, and the newline after a block is the caller's to drop,
+ * after the line-based passes that run later have seen it.
+ */
+export function renderMarkdownListsAndRules(text, { renderItem = value => value, wrap = html => html } = {}) {
+ const lines = String(text == null ? '' : text).split(/\r?\n/);
+ const output = [];
+ const render = list => {
+ const start = list.tag === 'ol' && list.start !== 1 ? ` start="${list.start}"` : '';
+ const items = list.items.map(item => `<li>${renderItem(item.lines.join('\n'))}${item.lists.map(render).join('')}</li>`);
+ return `<${list.tag}${start}>${items.join('')}</${list.tag}>`;
+ };
+ for (let index = 0; index < lines.length;) {
+ const line = lines[index];
+ if (MARKDOWN_RULE.test(line)) {
+ while (output.length && !output[output.length - 1].trim()) output.pop();
+ output.push(wrap('<hr>'));
+ index += 1;
+ while (index < lines.length && !lines[index].trim()) index += 1;
+ continue;
+ }
+ if (markdownListItem(line)) {
+ const { roots, next } = parseMarkdownList(lines, index);
+ output.push(wrap(roots.map(render).join('')));
+ index = next;
+ continue;
+ }
+ output.push(line);
+ index += 1;
+ }
+ return output.join('\n');
+}
+
/**
* Convert escaped Markdown blockquote lines (`&gt; text`) into blockquote
* elements. Showing the markers literally makes people copy them back into
diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.js
index 49ad29549..87a7aa185 100644
--- a/src/chrome/src/ui/sidepanel.js
+++ b/src/chrome/src/ui/sidepanel.js
@@ -17,7 +17,7 @@ import { t, getLocale, setLocale, LANGUAGES, applyDOMTranslations, translationsF
import { CAPABILITY_LABEL, PERMISSION_GATE_SESSION_OFF_KEY, uploadApprovalCard } from '../agent/permission-gate.js';
import { sanitizeMarkdownLinks, linkifyPlainUrls } from './markdown-link.js';
import { installChatLinkIcons } from './chat-link-icons.js';
-import { codeFenceLanguage, createMarkdownPlaceholders, highlightCode, renderMarkdownBlockquotes, renderMarkdownHeadings, renderMarkdownTables, replaceInlineDollarMath, replaceMarkdownCodeFences } from './markdown-render.js';
+import { codeFenceLanguage, createMarkdownPlaceholders, highlightCode, renderMarkdownBlockquotes, renderMarkdownHeadings, renderMarkdownListsAndRules, renderMarkdownTables, replaceInlineDollarMath, replaceMarkdownCodeFences } from './markdown-render.js';
import { applyMode, loadMode, watch } from './theme.js';
import {
UI_SCALE_LEVELS,
@@ -15134,22 +15134,36 @@ function formatMarkdown(text, options = {}) {
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
- // 4. Tables, then headings, inline formatting, markdown link sanitization,
- // then newline β†’ <br>. Headings swallow their trailing newline, so tables
- // must run first or a table on the next line is glued onto the heading.
+ // 4. Tables, then lists and --- rules, quotes, headings, inline formatting,
+ // markdown link sanitization, then newline β†’ <br>. Quotes and headings
+ // swallow their trailing newline, so tables and lists must run first or a
+ // table or list on the next line is glued onto them.
// Code and inline-code placeholders were extracted above, so
// Markdown-looking source inside them is not interpreted here.
- text = renderMarkdownTables(text);
- text = renderMarkdownBlockquotes(text);
- text = renderMarkdownHeadings(text);
const emphasis = value => value
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
.replace(/\*(.+?)\*/g, '<em>$1</em>');
// Protect destinations from emphasis (a URL can itself contain '*').
- text = linkifyPlainUrls(sanitizeMarkdownLinks(text)).replace(/(<a\b[^>]*>)([\s\S]*?)(<\/a>)/g, (_match, open, label, close) => (
+ const inline = value => emphasis(linkifyPlainUrls(sanitizeMarkdownLinks(value)).replace(/(<a\b[^>]*>)([\s\S]*?)(<\/a>)/g, (_match, open, label, close) => (
placeholders.add(`${open}${/^https?:\/\/\S+$/i.test(label) ? label : emphasis(label)}${close}`)
- ));
- text = emphasis(text).replace(/\n/g, '<br>');
+ )));
+ text = renderMarkdownTables(text);
+ // Each list item is formatted on its own, so a * bullet never pairs with an
+ // emphasis marker in another item.
+ const blocks = [];
+ text = renderMarkdownListsAndRules(text, {
+ renderItem: value => inline(value).replace(/\n/g, '<br>'),
+ wrap: html => {
+ const token = placeholders.add(html);
+ blocks.push(token);
+ return token;
+ },
+ });
+ text = renderMarkdownBlockquotes(text);
+ text = renderMarkdownHeadings(text);
+ // A list or rule is a block: the newline after it is not a line break.
+ for (const token of blocks) text = text.split(`${token}\n`).join(token);
+ text = inline(text).replace(/\n/g, '<br>');
text = placeholders.restore(text);
// Schedule KaTeX rendering of any math expressions in the messages area.
diff --git a/src/chrome/styles/sidepanel.css b/src/chrome/styles/sidepanel.css
index 1c74bc942..18328af6d 100644
--- a/src/chrome/styles/sidepanel.css
+++ b/src/chrome/styles/sidepanel.css
@@ -4244,6 +4244,28 @@ html[data-ui-scale="175"] .composer-toolbar {
color: inherit;
}
+.message-content ul,
+.message-content ol {
+ margin: 4px 0;
+ padding-left: 20px;
+}
+
+.message-content li {
+ margin: 2px 0;
+}
+
+.message-content li > ul,
+.message-content li > ol {
+ margin: 2px 0;
+}
+
+.message-content hr {
+ height: 0;
+ margin: 10px 0;
+ border: 0;
+ border-top: 1px solid var(--border);
+}
+
.markdown-table-wrapper {
max-width: 100%;
margin: 8px 0;
diff --git a/src/firefox/src/ui/history-text.js b/src/firefox/src/ui/history-text.js
index dc19024a6..10d43b92d 100644
--- a/src/firefox/src/ui/history-text.js
+++ b/src/firefox/src/ui/history-text.js
@@ -134,9 +134,11 @@ export function historyTextFromElement(root, { markdown = true } = {}) {
return;
}
if (tagName === 'HR') {
+ // Blank lines around it keep a saved rule from reading as the underline
+ // of a heading on the line above.
ensureBreak();
- output += '---';
- appendHardBreak();
+ if (output && !output.endsWith('\n\n')) output += '\n';
+ output += '---\n\n';
return;
}
@@ -194,6 +196,28 @@ export function historyTextFromElement(root, { markdown = true } = {}) {
if (href) output += `](${href})`;
return;
}
+ if (markdown && (tagName === 'UL' || tagName === 'OL')) {
+ // A rendered list goes back to Markdown the panel renders as one: a
+ // marker per item, and its further lines and nested lists indented
+ // under the marker.
+ const ordered = tagName === 'OL';
+ let number = Number.parseInt(String(node.getAttribute?.('start') ?? '1'), 10);
+ if (!Number.isSafeInteger(number) || number < 0) number = 1;
+ const items = [];
+ for (const item of elementChildren(node)) {
+ if (String(item.tagName || '').toUpperCase() !== 'LI') continue;
+ const marker = ordered ? `${number++}. ` : '- ';
+ const body = historyTextFromElement(item, { markdown: true }).replace(/^\n+|\s+$/g, '');
+ items.push(marker + body.split('\n')
+ .map((line, index) => (index && line ? ' '.repeat(marker.length) + line : line)).join('\n'));
+ }
+ if (items.length) {
+ ensureBreak();
+ output += items.join('\n');
+ ensureBreak();
+ }
+ return;
+ }
if (markdown && (tagName === 'TABLE' || node.classList?.contains?.('markdown-table-wrapper'))) {
const markdownTable = markdownTableFromElement(tableElementFromNode(node) || node);
if (markdownTable) {
diff --git a/src/firefox/src/ui/markdown-render.js b/src/firefox/src/ui/markdown-render.js
index 21f529681..b337cc476 100644
--- a/src/firefox/src/ui/markdown-render.js
+++ b/src/firefox/src/ui/markdown-render.js
@@ -850,6 +850,115 @@ export function highlightCode(code, language) {
}
}
+// A thematic break: three or more -, * or _ alone on a line ("---", "* * *").
+const MARKDOWN_RULE = /^[ \t]{0,3}([-*_])(?:[ \t]*\1){2,}[ \t]*$/;
+// A bullet (-, * or +) or numbered (1. or 1)) list item with its text.
+const MARKDOWN_LIST_ITEM = /^([ \t]*)([-*+]|\d{1,9}[.)])[ \t]+(\S.*)$/;
+
+function markdownIndent(line) {
+ let width = 0;
+ for (const character of /^[ \t]*/.exec(line)[0]) width += character === '\t' ? 4 - (width % 4) : 1;
+ return width;
+}
+
+function markdownListItem(line) {
+ const match = MARKDOWN_LIST_ITEM.exec(line);
+ if (!match || MARKDOWN_RULE.test(line)) return null;
+ const ordered = /\d/.test(match[2]);
+ return {
+ indent: markdownIndent(line),
+ tag: ordered ? 'ol' : 'ul',
+ number: ordered ? Number.parseInt(match[2], 10) : 1,
+ text: match[3],
+ };
+}
+
+// One list block from lines[start]: nested by indentation, items continued by
+// indented lines, kept open across blank lines that more of it follows.
+function parseMarkdownList(lines, start) {
+ const roots = [];
+ const open = [];
+ const openList = (item, owner) => {
+ const list = { tag: item.tag, start: item.number, indent: item.indent, items: [] };
+ (owner ? owner.lists : roots).push(list);
+ open.push(list);
+ return list;
+ };
+ let index = start;
+ while (index < lines.length) {
+ const line = lines[index];
+ if (!line.trim()) {
+ let next = index + 1;
+ while (next < lines.length && !lines[next].trim()) next += 1;
+ const following = lines[next];
+ if (following === undefined || MARKDOWN_RULE.test(following)
+ || (!markdownListItem(following) && markdownIndent(following) === 0)) break;
+ index = next;
+ continue;
+ }
+ if (MARKDOWN_RULE.test(line)) break;
+ const item = markdownListItem(line);
+ if (item) {
+ while (open.length && open[open.length - 1].indent > item.indent) open.pop();
+ let list = open[open.length - 1];
+ if (!list) list = openList(item, null);
+ else if (item.indent > list.indent) list = openList(item, list.items[list.items.length - 1]);
+ else if (list.tag !== item.tag) {
+ open.pop();
+ const parent = open[open.length - 1];
+ list = openList(item, parent ? parent.items[parent.items.length - 1] : null);
+ }
+ list.items.push({ lines: [item.text], lists: [] });
+ index += 1;
+ continue;
+ }
+ // Indented text continues the innermost item; unindented text ends the list.
+ if (!open.length || markdownIndent(line) === 0) break;
+ const list = open[open.length - 1];
+ list.items[list.items.length - 1].lines.push(line.trim());
+ index += 1;
+ }
+ return { roots, next: index };
+}
+
+/**
+ * Convert escaped Markdown bullet and numbered lists (nested by indentation)
+ * and thematic breaks (---) into <ul>/<ol> and <hr>. renderItem formats one
+ * item's text, whose lines it receives joined by \n; wrap receives each
+ * finished block and returns what stands for it in the text, so a caller can
+ * keep later passes out of it. A block keeps its own line: blank lines around
+ * a rule are dropped, and the newline after a block is the caller's to drop,
+ * after the line-based passes that run later have seen it.
+ */
+export function renderMarkdownListsAndRules(text, { renderItem = value => value, wrap = html => html } = {}) {
+ const lines = String(text == null ? '' : text).split(/\r?\n/);
+ const output = [];
+ const render = list => {
+ const start = list.tag === 'ol' && list.start !== 1 ? ` start="${list.start}"` : '';
+ const items = list.items.map(item => `<li>${renderItem(item.lines.join('\n'))}${item.lists.map(render).join('')}</li>`);
+ return `<${list.tag}${start}>${items.join('')}</${list.tag}>`;
+ };
+ for (let index = 0; index < lines.length;) {
+ const line = lines[index];
+ if (MARKDOWN_RULE.test(line)) {
+ while (output.length && !output[output.length - 1].trim()) output.pop();
+ output.push(wrap('<hr>'));
+ index += 1;
+ while (index < lines.length && !lines[index].trim()) index += 1;
+ continue;
+ }
+ if (markdownListItem(line)) {
+ const { roots, next } = parseMarkdownList(lines, index);
+ output.push(wrap(roots.map(render).join('')));
+ index = next;
+ continue;
+ }
+ output.push(line);
+ index += 1;
+ }
+ return output.join('\n');
+}
+
/**
* Convert escaped Markdown blockquote lines (`&gt; text`) into blockquote
* elements. Showing the markers literally makes people copy them back into
diff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.js
index d6f0ef4f2..d637cfa37 100644
--- a/src/firefox/src/ui/sidepanel.js
+++ b/src/firefox/src/ui/sidepanel.js
@@ -16,7 +16,7 @@ import { t, getLocale, setLocale, LANGUAGES, applyDOMTranslations, translationsF
import { CAPABILITY_LABEL, PERMISSION_GATE_SESSION_OFF_KEY, uploadApprovalCard } from '../agent/permission-gate.js';
import { sanitizeMarkdownLinks, linkifyPlainUrls } from './markdown-link.js';
import { installChatLinkIcons } from './chat-link-icons.js';
-import { codeFenceLanguage, createMarkdownPlaceholders, highlightCode, renderMarkdownBlockquotes, renderMarkdownHeadings, renderMarkdownTables, replaceInlineDollarMath, replaceMarkdownCodeFences } from './markdown-render.js';
+import { codeFenceLanguage, createMarkdownPlaceholders, highlightCode, renderMarkdownBlockquotes, renderMarkdownHeadings, renderMarkdownListsAndRules, renderMarkdownTables, replaceInlineDollarMath, replaceMarkdownCodeFences } from './markdown-render.js';
import { applyMode, loadMode, watch } from './theme.js';
import {
UI_SCALE_LEVELS,
@@ -14751,22 +14751,36 @@ function formatMarkdown(text, options = {}) {
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
- // 4. Tables, then headings, inline formatting, markdown link sanitization,
- // then newline β†’ <br>. Headings swallow their trailing newline, so tables
- // must run first or a table on the next line is glued onto the heading.
+ // 4. Tables, then lists and --- rules, quotes, headings, inline formatting,
+ // markdown link sanitization, then newline β†’ <br>. Quotes and headings
+ // swallow their trailing newline, so tables and lists must run first or a
+ // table or list on the next line is glued onto them.
// Code and inline-code placeholders were extracted above, so
// Markdown-looking source inside them is not interpreted here.
- text = renderMarkdownTables(text);
- text = renderMarkdownBlockquotes(text);
- text = renderMarkdownHeadings(text);
const emphasis = value => value
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
.replace(/\*(.+?)\*/g, '<em>$1</em>');
// Protect destinations from emphasis (a URL can itself contain '*').
- text = linkifyPlainUrls(sanitizeMarkdownLinks(text)).replace(/(<a\b[^>]*>)([\s\S]*?)(<\/a>)/g, (_match, open, label, close) => (
+ const inline = value => emphasis(linkifyPlainUrls(sanitizeMarkdownLinks(value)).replace(/(<a\b[^>]*>)([\s\S]*?)(<\/a>)/g, (_match, open, label, close) => (
placeholders.add(`${open}${/^https?:\/\/\S+$/i.test(label) ? label : emphasis(label)}${close}`)
- ));
- text = emphasis(text).replace(/\n/g, '<br>');
+ )));
+ text = renderMarkdownTables(text);
+ // Each list item is formatted on its own, so a * bullet never pairs with an
+ // emphasis marker in another item.
+ const blocks = [];
+ text = renderMarkdownListsAndRules(text, {
+ renderItem: value => inline(value).replace(/\n/g, '<br>'),
+ wrap: html => {
+ const token = placeholders.add(html);
+ blocks.push(token);
+ return token;
+ },
+ });
+ text = renderMarkdownBlockquotes(text);
+ text = renderMarkdownHeadings(text);
+ // A list or rule is a block: the newline after it is not a line break.
+ for (const token of blocks) text = text.split(`${token}\n`).join(token);
+ text = inline(text).replace(/\n/g, '<br>');
text = placeholders.restore(text);
// Schedule KaTeX rendering of any math expressions in the messages area.
diff --git a/src/firefox/styles/sidepanel.css b/src/firefox/styles/sidepanel.css
index d2aeea1bf..d121cd579 100644
--- a/src/firefox/styles/sidepanel.css
+++ b/src/firefox/styles/sidepanel.css
@@ -4071,6 +4071,28 @@ html[data-ui-scale="175"] .composer-toolbar {
color: inherit;
}
+.message-content ul,
+.message-content ol {
+ margin: 4px 0;
+ padding-left: 20px;
+}
+
+.message-content li {
+ margin: 2px 0;
+}
+
+.message-content li > ul,
+.message-content li > ol {
+ margin: 2px 0;
+}
+
+.message-content hr {
+ height: 0;
+ margin: 10px 0;
+ border: 0;
+ border-top: 1px solid var(--border);
+}
+
.markdown-table-wrapper {
max-width: 100%;
margin: 8px 0;
diff --git a/test/markdown-render.mjs b/test/markdown-render.mjs
index 171794709..c58f49650 100644
--- a/test/markdown-render.mjs
+++ b/test/markdown-render.mjs
@@ -235,7 +235,7 @@ for (const build of ['chrome', 'firefox']) {
[
'numbered list',
'1. ```python\n value = "**literal**"\n ```\n\n2. Start the server.',
- /2\. Start the server\./,
+ /<\/pre><\/div><\/li><li>Start the server\.<\/li><\/ol>/,
/<ol><li><pre><code>value = &quot;\*\*literal\*\*&quot;\n<\/code><\/pre><\/li><\/ol><br><br><ol><li>Start the server\.<\/li><\/ol>/,
],
[
@@ -724,6 +724,73 @@ for (const build of ['chrome', 'firefox']) {
assert.match(formatMarkdown(saved), /traces \\\(\\rightarrow\\\) rotation, \$\$a\^2\$\$/);
});
+ test(`${build}: bullet and numbered lists nest by indentation; --- is a rule`, () => {
+ const blocks = [];
+ const render = source => helpers.renderMarkdownListsAndRules(source, {
+ renderItem: value => value.replace(/\n/g, '<br>'),
+ wrap: html => { blocks.push(html); return `[${html}]`; },
+ });
+ assert.equal(render('- a\n* b\n+ c'), '[<ul><li>a</li><li>b</li><li>c</li></ul>]');
+ assert.equal(render('3. three\n4) four'), '[<ol start="3"><li>three</li><li>four</li></ol>]');
+ assert.equal(
+ render('* parent\n 1. first\n 2. second\n - deep\n* next'),
+ '[<ul><li>parent<ol><li>first</li><li>second<ul><li>deep</li></ul></li></ol></li><li>next</li></ul>]',
+ );
+ assert.equal(render('-\tTab item\n\t- nested'), '[<ul><li>Tab item<ul><li>nested</li></ul></li></ul>]');
+ assert.equal(render('1. one\n more of one\n2. two'), '[<ol><li>one<br>more of one</li><li>two</li></ol>]');
+ assert.equal(render('1. one\n\n2. two\n\nAfter'), '[<ol><li>one</li><li>two</li></ol>]\n\nAfter');
+ assert.equal(render('- a\n- b\nAfter'), '[<ul><li>a</li><li>b</li></ul>]\nAfter');
+ assert.equal(render('- a\n\n1. one'), '[<ul><li>a</li></ul><ol><li>one</li></ol>]');
+ assert.equal(render('Intro\n\n---\n\n### Next'), 'Intro\n[<hr>]\n### Next');
+ for (const rule of ['***', '* * *', '___', '- - -', '----------']) assert.equal(render(rule), '[<hr>]', rule);
+ assert.equal(render('- a\n---\n- b'), '[<ul><li>a</li></ul>]\n[<hr>]\n[<ul><li>b</li></ul>]');
+ for (const prose of ['*emphasis* here', '**Bold:** text', '-1 degrees', '2.5 GB', '--flag', '+1 vote', '- ', '*', '-- dash']) {
+ assert.equal(render(prose), prose, prose);
+ }
+ assert.ok(blocks.length > 0);
+ });
+
+ test(`${build}: side panel lists render items on their own, around headings, quotes and tables`, () => {
+ const source = [
+ 'Answers below.', '', '---', '', '### 1. Status',
+ '* **Ready:** the pipeline runs end to end, and `run` exports $\\alpha$ checkpoints.',
+ '* **Limits:**', ' * one * star here', ' * another * star', ' 1. first step', ' 2. second step',
+ '> quoted note', '| A | B |', '| --- | --- |', '| 1 | 2 |',
+ '- after the table', '## Next', '1. Ship it.',
+ ].join('\n');
+ const html = formatMarkdown(source);
+ assert.match(html, /^Answers below\.<br><hr><h3>1\. Status<\/h3><ul><li><strong>Ready:<\/strong> the pipeline runs end to end, and <code>run<\/code> exports \\\(\\alpha\\\) checkpoints\.<\/li><li><strong>Limits:<\/strong><ul><li>one \* star here<\/li><li>another \* star<\/li><\/ul><ol><li>first step<\/li><li>second step<\/li><\/ol><\/li><\/ul><blockquote>quoted note<\/blockquote>/);
+ assert.match(html, /<\/table><\/div><br><ul><li>after the table<\/li><\/ul><h2>Next<\/h2><ol><li>Ship it\.<\/li><\/ol>$/);
+ assert.doesNotMatch(html, /<em>/, 'a bullet or a lone * paired with another item');
+ // Streaming renders the same blocks, without the finishing passes.
+ assert.match(formatMarkdown('- a\n- b', { enhance: false }), /^<ul><li>a<\/li><li>b<\/li><\/ul>$/);
+ });
+
+ test(`${build}: history saves rendered lists and rules as Markdown that renders the same`, () => {
+ const text = value => ({ nodeType: 3, nodeValue: value, textContent: value });
+ const element = (tagName, attributes, ...childNodes) => ({
+ nodeType: 1, tagName, childNodes,
+ classList: { contains: () => false },
+ getAttribute: name => attributes?.[name] ?? null,
+ get textContent() { return childNodes.map(child => child.textContent).join(''); },
+ });
+ // formatMarkdown('Intro\n\n---\n\n* **a** one\n continued\n 3. three\n 4. four\n* b\n\nAfter')
+ const source = 'Intro\n\n---\n\n* **a** one\n continued\n 3. three\n 4. four\n* b\n\nAfter';
+ const rendered = formatMarkdown(source);
+ assert.equal(rendered, 'Intro<br><hr><ul><li><strong>a</strong> one<br>continued<ol start="3"><li>three</li><li>four</li></ol></li><li>b</li></ul><br>After');
+ const dom = element('DIV', null,
+ text('Intro'), element('BR'), element('HR'),
+ element('UL', null,
+ element('LI', null, element('STRONG', null, text('a')), text(' one'), element('BR'), text('continued'),
+ element('OL', { start: '3' }, element('LI', null, text('three')), element('LI', null, text('four')))),
+ element('LI', null, text('b'))),
+ element('BR'), text('After'));
+ const saved = historyTextFromElement(dom);
+ assert.equal(saved, 'Intro\n\n---\n\n- **a** one\n continued\n 3. three\n 4. four\n- b\n\nAfter');
+ assert.equal(formatMarkdown(saved), rendered);
+ assert.equal(historyTextFromElement(dom, { markdown: false }).includes('- '), false, 'plain roles gain no list markers');
+ });
+
if (process.env.WEBBRAIN_MARKDOWN_DOM === '1') test(`${build}: browser renders inline TeX with KaTeX and saves it back`, async () => {
const { chromium, firefox } = await import('playwright');
const browser = await (build === 'chrome' ? chromium : firefox).launch({ headless: true });
@@ -766,6 +833,60 @@ for (const build of ['chrome', 'firefox']) {
}
});
+ if (process.env.WEBBRAIN_MARKDOWN_DOM === '1') test(`${build}: browser shows lists and rules and saves them back`, async () => {
+ const { chromium, firefox } = await import('playwright');
+ const browser = await (build === 'chrome' ? chromium : firefox).launch({ headless: true });
+ try {
+ const page = await browser.newPage({ viewport: { width: 420, height: 900 } });
+ await page.route('http://markdown.test/**', async route => {
+ const name = new URL(route.request().url()).pathname.slice(1);
+ if (/^[\w-]+\.js$/.test(name)) {
+ await route.fulfill({ contentType: 'text/javascript', body: readUi(build, name) });
+ } else {
+ await route.fulfill({ contentType: 'text/html', body: '<!doctype html><html data-theme="light"><body><div id="messages"><div class="message assistant"><div class="message-content"><div class="message-text" id="message"></div></div></div></div></body></html>' });
+ }
+ });
+ await page.goto('http://markdown.test/');
+ await page.addStyleTag({ content: fs.readFileSync(new URL(`../src/${build}/styles/sidepanel.css`, import.meta.url), 'utf8') });
+ const source = [
+ 'Answers below.', '', '---', '', '### 1. Status',
+ '* **Ready:** the pipeline runs end to end.',
+ '* **Limits:**', ' * one validated model', ' * slow with thinking on',
+ '', '---', '', '### 2. Next steps', '1. **Set up:** run `setup.sh`.', '2. **Smoke test:** run the tiny model.',
+ ].join('\n');
+ const result = await page.evaluate(async ({ formatter, source }) => {
+ const helpers = await import('/markdown-render.js');
+ const { sanitizeMarkdownLinks, linkifyPlainUrls } = await import('/markdown-link.js');
+ const { escapeHtml } = await import('/utils.js');
+ const { historyTextFromElement } = await import('/history-text.js');
+ const dependencies = { ...helpers, sanitizeMarkdownLinks, linkifyPlainUrls, escapeHtml, t: key => key, scheduleMathRender() {} };
+ const format = new Function(...Object.keys(dependencies), `return (${formatter})`)(...Object.values(dependencies));
+ const message = document.querySelector('#message');
+ message.innerHTML = format(source);
+ const first = message.innerHTML;
+ const rule = message.querySelector('hr');
+ const shown = {
+ lists: message.querySelectorAll('ul').length,
+ ordered: message.querySelectorAll('ol').length,
+ items: message.querySelectorAll('li').length,
+ rules: message.querySelectorAll('hr').length,
+ bullet: getComputedStyle(message.querySelector('ul > li')).listStyleType,
+ number: getComputedStyle(message.querySelector('ol > li')).listStyleType,
+ ruleShown: rule.getBoundingClientRect().width > 100 && getComputedStyle(rule).borderTopStyle === 'solid',
+ literalMarkers: /(^|\n)\s*(\*|-{3})\s/.test(message.innerText),
+ };
+ message.innerHTML = format(historyTextFromElement(message));
+ return { ...shown, roundTrip: message.innerHTML === first };
+ }, { formatter: panelFormatter(build), source });
+ assert.deepEqual(result, { lists: 2, ordered: 1, items: 6, rules: 2, bullet: 'disc', number: 'decimal', ruleShown: true, literalMarkers: false, roundTrip: true });
+ if (process.env.WEBBRAIN_MARKDOWN_SCREENSHOT_DIR) {
+ await page.locator('#messages').screenshot({ path: `${process.env.WEBBRAIN_MARKDOWN_SCREENSHOT_DIR}/${build}-lists.png` });
+ }
+ } finally {
+ await browser.close();
+ }
+ });
+
// Opt-in native DOM checks: WEBBRAIN_MARKDOWN_DOM=1 npm run test:markdown.
if (process.env.WEBBRAIN_MARKDOWN_DOM === '1') test(`${build}: browser render, Copy and history round trip`, async () => {
const { chromium, firefox } = await import('playwright');
diff --git a/test/run.js b/test/run.js
index a66b21f42..be4f97ed0 100644
--- a/test/run.js
+++ b/test/run.js
@@ -22505,10 +22505,10 @@ test('sidepanels wire highlighting and heading rendering into fenced Markdown',
]) {
const panel = fs.readFileSync(path.join(ROOT, panelRel), 'utf8');
const css = fs.readFileSync(path.join(ROOT, cssRel), 'utf8');
- assert.match(panel, /import \{ codeFenceLanguage, createMarkdownPlaceholders, highlightCode, renderMarkdownBlockquotes, renderMarkdownHeadings, renderMarkdownTables, replaceInlineDollarMath, replaceMarkdownCodeFences \} from '\.\/markdown-render\.js';/, `${label}: renderer helpers should be imported`);
+ assert.match(panel, /import \{ codeFenceLanguage, createMarkdownPlaceholders, highlightCode, renderMarkdownBlockquotes, renderMarkdownHeadings, renderMarkdownListsAndRules, renderMarkdownTables, replaceInlineDollarMath, replaceMarkdownCodeFences \} from '\.\/markdown-render\.js';/, `${label}: renderer helpers should be imported`);
assert.match(panel, /const lang = codeFenceLanguage\(info\);/, `${label}: fenced code should tolerate metadata after its language token`);
assert.match(panel, /const highlighted = enhance \? highlightCode\(code, lang\) : escapeHtml\(code\);/, `${label}: completed fenced code should be highlighted by its language while live code stays lightweight`);
- assert.match(panel, /text = renderMarkdownTables\(text\);\s*text = renderMarkdownBlockquotes\(text\);\s*text = renderMarkdownHeadings\(text\);/, `${label}: pipe tables and quotes must render before headings swallow the following newline`);
+ assert.match(panel, /text = renderMarkdownTables\(text\);[\s\S]{0,400}?text = renderMarkdownListsAndRules\(text, \{[\s\S]{0,400}?text = renderMarkdownBlockquotes\(text\);\s*text = renderMarkdownHeadings\(text\);/, `${label}: pipe tables, lists and quotes must render before headings swallow the following newline`);
assert.match(css, /\.message-content blockquote \{[\s\S]*?border-left: 3px solid var\(--border\);/, `${label}: rendered quotes should be visually distinct`);
assert.match(css, /\.message-content table \{[\s\S]*?border-collapse: collapse;/, `${label}: rendered tables should have readable borders`);
assert.match(css, /\.syntax-keyword[\s\S]*?var\(--syntax-keyword\)/, `${label}: token colors should be styled`);