From f4fa69ed56231d04067f20bcf8b68e01eb000f73 Mon Sep 17 00:00:00 2001 From: Omar Zunic Date: Thu, 12 Nov 2026 11:26:18 +0100 Subject: [PATCH 1/3] fix(assistant): render
and wrap the share banner The model writes
for a line break, for example in a poem. The inline parsers of the web app and the mobile app do not read HTML, so the chat showed the tag as text. Both parsers now change a
to a line break after the inline split, so an italic span over a
stays one span. On a phone, the banner of a shared chat put the text and the buttons in one row, and the text became a narrow column. The text group now has a minimum width, so the buttons wrap to their own row. --- apps/mobile/src/assistant/markdown.test.ts | 6 +++++ apps/mobile/src/assistant/markdown.ts | 5 +++- apps/web/src/components/assistant/answer.tsx | 12 ++++++--- .../routes/$orgSlug/assistant_/shared/$id.tsx | 25 +++++++++++-------- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/apps/mobile/src/assistant/markdown.test.ts b/apps/mobile/src/assistant/markdown.test.ts index 64a1cdde..2ad444fc 100644 --- a/apps/mobile/src/assistant/markdown.test.ts +++ b/apps/mobile/src/assistant/markdown.test.ts @@ -145,6 +145,12 @@ describe("parseInline", () => { ]); }); + test("a
is a line break, also inside an italic span", () => { + expect(parseInline("*one,
two
three*")).toEqual([ + { kind: "italic", text: "one,\ntwo\nthree" }, + ]); + }); + test("a link that is not a web link does not open", () => { expect(parseInline("[x](javascript:alert(1))")[0]).toMatchObject({ kind: "link", diff --git a/apps/mobile/src/assistant/markdown.ts b/apps/mobile/src/assistant/markdown.ts index d56c3d4a..bc6c94e2 100644 --- a/apps/mobile/src/assistant/markdown.ts +++ b/apps/mobile/src/assistant/markdown.ts @@ -332,7 +332,10 @@ const INLINE = * another. */ export const parseInline = (text: string): Inline[] => { const parts: Inline[] = []; - for (const part of text.split(INLINE)) { + // Models write `
` for a line break. Replace it after the split, so that + // a `*...*` span over a `
` stays one span. + for (const raw of text.split(INLINE)) { + const part = raw.replace(/\n?/gi, "\n"); if (part === "") continue; if (part.startsWith("`") && part.endsWith("`") && part.length > 2) { parts.push({ kind: "code", text: part.slice(1, -1) }); diff --git a/apps/web/src/components/assistant/answer.tsx b/apps/web/src/components/assistant/answer.tsx index f745de54..c1262675 100644 --- a/apps/web/src/components/assistant/answer.tsx +++ b/apps/web/src/components/assistant/answer.tsx @@ -151,10 +151,16 @@ const revealWords = (part: string, at: number) => { * cumulative WORD count is stable instead — a closing `**` that finally lands * re-splits the line around itself without changing how many words are on it, * because the marker's characters belong to the word they are attached to. */ +const BR = /\n?/gi; + const renderInline = (text: string, reveal = false) => { - const parts = text.split( - /(`[^`]+`|\*\*[^*]+\*\*|\*[^*\n]+\*|\[\[\d{4}-\d{2}-\d{2}\]\]|\[[^\]\n]+\]\([^)\s]+\))/g, - ); + // Models write `
` for a line break. Replace it after the split, so that + // a `*...*` span over a `
` stays one span. + const parts = text + .split( + /(`[^`]+`|\*\*[^*]+\*\*|\*[^*\n]+\*|\[\[\d{4}-\d{2}-\d{2}\]\]|\[[^\]\n]+\]\([^)\s]+\))/g, + ) + .map((part) => part.replace(BR, "\n")); let cursor = 0; return parts.map((part, index) => { const at = cursor; diff --git a/apps/web/src/routes/$orgSlug/assistant_/shared/$id.tsx b/apps/web/src/routes/$orgSlug/assistant_/shared/$id.tsx index b45963f3..ae91bd0a 100644 --- a/apps/web/src/routes/$orgSlug/assistant_/shared/$id.tsx +++ b/apps/web/src/routes/$orgSlug/assistant_/shared/$id.tsx @@ -163,17 +163,20 @@ function SharedChatPage() {
- - - {data.sharedBy.image && ( - - )} - {data.sharedBy.name.slice(0, 1)} - -

- Shared by {data.sharedBy.name} on . It - can show data that you cannot normally see. -

+ {/* The min width wraps the buttons to their own row on a phone. */} +
+ + + {data.sharedBy.image && ( + + )} + {data.sharedBy.name.slice(0, 1)} + +

+ Shared by {data.sharedBy.name} on . + It can show data that you cannot normally see. +

+
{isAdmin && }
From 8c14e274c2b3164bc40f06a22a3e3bc0a7c1cd77 Mon Sep 17 00:00:00 2001 From: Omar Zunic Date: Tue, 17 Nov 2026 12:58:06 +0100 Subject: [PATCH 2/3] fix(assistant): keep renderInline doc comment attached The BR constant sat between the doc comment and renderInline. Move the constant above the comment so the comment documents the function. --- apps/web/src/components/assistant/answer.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/assistant/answer.tsx b/apps/web/src/components/assistant/answer.tsx index c1262675..87c5b666 100644 --- a/apps/web/src/components/assistant/answer.tsx +++ b/apps/web/src/components/assistant/answer.tsx @@ -141,6 +141,8 @@ const revealWords = (part: string, at: number) => { )); }; +const BR = /\n?/gi; + /** Inline `code`, **bold**, *italic*, [links](…) and `[[date]]` citations, in * one pass so none of them can swallow another. * @@ -151,8 +153,6 @@ const revealWords = (part: string, at: number) => { * cumulative WORD count is stable instead — a closing `**` that finally lands * re-splits the line around itself without changing how many words are on it, * because the marker's characters belong to the word they are attached to. */ -const BR = /\n?/gi; - const renderInline = (text: string, reveal = false) => { // Models write `
` for a line break. Replace it after the split, so that // a `*...*` span over a `
` stays one span. From 792b5d8da337c145e9da130c62def0bb682b0aa1 Mon Sep 17 00:00:00 2001 From: Omar Zunic Date: Tue, 17 Nov 2026 13:05:55 +0100 Subject: [PATCH 3/3] fix(assistant): break lines in cells, not code spans The
replacement gave a newline, but only the plain paragraph showed it. Table cells, list items and headings collapsed it to a space. Add whitespace-pre-line to those wrappers. A no-wrap table column uses whitespace-pre, which keeps the break and the no-wrap. The replacement also ran inside inline code spans. Skip a code part on web and on mobile, so `a
b` stays literal. --- apps/mobile/src/assistant/markdown.test.ts | 7 ++++ apps/mobile/src/assistant/markdown.ts | 4 ++- .../components/assistant/answer-br.test.tsx | 34 +++++++++++++++++++ apps/web/src/components/assistant/answer.tsx | 15 +++++--- 4 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 apps/web/src/components/assistant/answer-br.test.tsx diff --git a/apps/mobile/src/assistant/markdown.test.ts b/apps/mobile/src/assistant/markdown.test.ts index 2ad444fc..ceb1b725 100644 --- a/apps/mobile/src/assistant/markdown.test.ts +++ b/apps/mobile/src/assistant/markdown.test.ts @@ -151,6 +151,13 @@ describe("parseInline", () => { ]); }); + test("a
in a code span stays literal", () => { + expect(parseInline("`a
b`
c")).toEqual([ + { kind: "code", text: "a
b" }, + { kind: "text", text: "\nc" }, + ]); + }); + test("a link that is not a web link does not open", () => { expect(parseInline("[x](javascript:alert(1))")[0]).toMatchObject({ kind: "link", diff --git a/apps/mobile/src/assistant/markdown.ts b/apps/mobile/src/assistant/markdown.ts index bc6c94e2..d255def8 100644 --- a/apps/mobile/src/assistant/markdown.ts +++ b/apps/mobile/src/assistant/markdown.ts @@ -335,7 +335,9 @@ export const parseInline = (text: string): Inline[] => { // Models write `
` for a line break. Replace it after the split, so that // a `*...*` span over a `
` stays one span. for (const raw of text.split(INLINE)) { - const part = raw.replace(/\n?/gi, "\n"); + const part = raw.startsWith("`") + ? raw + : raw.replace(/\n?/gi, "\n"); if (part === "") continue; if (part.startsWith("`") && part.endsWith("`") && part.length > 2) { parts.push({ kind: "code", text: part.slice(1, -1) }); diff --git a/apps/web/src/components/assistant/answer-br.test.tsx b/apps/web/src/components/assistant/answer-br.test.tsx new file mode 100644 index 00000000..55c64522 --- /dev/null +++ b/apps/web/src/components/assistant/answer-br.test.tsx @@ -0,0 +1,34 @@ +// A model's `
` is a line break in a table cell, and literal in a code span. + +import { afterAll, beforeAll, describe, expect, test } from "bun:test"; + +import { GlobalRegistrator } from "@happy-dom/global-registrator"; +import { renderToStaticMarkup } from "react-dom/server"; + +let html: (text: string) => string; + +beforeAll(async () => { + // `answer.tsx` reads `window` when it loads, so import it after the fake DOM. + GlobalRegistrator.register(); + const { Answer } = await import("./answer.tsx"); + html = (text) => renderToStaticMarkup(); +}); + +afterAll(async () => { + await GlobalRegistrator.unregister(); +}); + +describe("Answer
", () => { + test("a table cell keeps the break and shows it", () => { + const out = html("| A | B |\n|---|---|\n| one
two | x |"); + expect(out).toContain("one\ntwo"); + expect(out).toContain("whitespace-pre"); + expect(out).not.toContain("<br"); + }); + + test("a code span keeps the tag literal", () => { + const out = html("see `a
b` here"); + expect(out).toContain("a<br>b"); + expect(out).not.toContain("a\nb"); + }); +}); diff --git a/apps/web/src/components/assistant/answer.tsx b/apps/web/src/components/assistant/answer.tsx index 87c5b666..8ef3aec4 100644 --- a/apps/web/src/components/assistant/answer.tsx +++ b/apps/web/src/components/assistant/answer.tsx @@ -160,7 +160,7 @@ const renderInline = (text: string, reveal = false) => { .split( /(`[^`]+`|\*\*[^*]+\*\*|\*[^*\n]+\*|\[\[\d{4}-\d{2}-\d{2}\]\]|\[[^\]\n]+\]\([^)\s]+\))/g, ) - .map((part) => part.replace(BR, "\n")); + .map((part) => (part.startsWith("`") ? part : part.replace(BR, "\n"))); let cursor = 0; return parts.map((part, index) => { const at = cursor; @@ -313,7 +313,8 @@ function AnswerTable({ return [ alignClass[column?.align ?? "left"], column?.numeric === true ? "tabular-nums" : "", - column?.wraps === false ? "whitespace-nowrap" : "", + // Both keep a `
` break. Only `pre` stops a wrap. + column?.wraps === false ? "whitespace-pre" : "whitespace-pre-line", // A floor under the PROSE column only, for the phone: five columns // cannot all fit there, and prose is the only one allowed to shrink, so // it collapses into a two-word ribbon forty lines deep while every short @@ -566,7 +567,7 @@ export function Answer({ return (
{renderInline(block.text, reveal)}
@@ -584,7 +585,9 @@ export function Answer({ {itemIndex + 1}. - {renderInline(item, reveal)} + + {renderInline(item, reveal)} + ))} @@ -603,7 +606,9 @@ export function Answer({ aria-hidden className="mt-[7px] size-1 shrink-0 rounded-full bg-ink-3" /> - {renderInline(item, reveal)} + + {renderInline(item, reveal)} + ))}