Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(editor): render code blocks when lowlight highlightAuto returns empty tree (#3358)
Naiyuan Qing85daf7818aa7
diff --git a/packages/views/editor/readonly-content.test.tsx b/packages/views/editor/readonly-content.test.tsxindex f2a5dca5d0..3489c27848 100644--- a/packages/views/editor/readonly-content.test.tsx+++ b/packages/views/editor/readonly-content.test.tsx@@ -151,6 +151,15 @@ describe("ReadonlyContent code styling", () => {expect(blockCode?.textContent).toBe(literalCode);});+ it("renders code blocks without a language tag (lowlight highlightAuto fallback)", () => {+ const token = "mul_407ec1e4464b580304362ed749f821901fd7d310";+ const { container } = render(+ <ReadonlyContent content={["```", token, "```"].join("\n")} />,+ );+ const blockCode = container.querySelector("pre code");+ expect(blockCode?.textContent?.trim()).toBe(token);+ });+it("keeps editor code literal by disabling font ligatures", () => {const codeCss = readFileSync("editor/styles/code.css", "utf8");diff --git a/packages/views/editor/readonly-content.tsx b/packages/views/editor/readonly-content.tsxindex d768654aa4..602071eb01 100644--- a/packages/views/editor/readonly-content.tsx+++ b/packages/views/editor/readonly-content.tsx@@ -242,20 +242,23 @@ function buildComponents(): Partial<Components> {const tree = lang? lowlight.highlight(lang, code): lowlight.highlightAuto(code);- return (- <code- className={cn("hljs", lang && `language-${lang}`)}- dangerouslySetInnerHTML={{ __html: toHtml(tree) }}- />- );+ const html = toHtml(tree);+ if (html) {+ return (+ <code+ className={cn("hljs", lang && `language-${lang}`)}+ dangerouslySetInnerHTML={{ __html: html }}+ />+ );+ }} catch {- // Fallback — render without highlighting- return (- <code className={className} {...props}>- {children}- </code>- );+ // fall through to plain render}+ return (+ <code className={cn("hljs", className)} {...props}>+ {children}+ </code>+ );},// Pre — pass through (CSS handles styling via .rich-text-editor pre).