Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix(a11y): clamp MarkdownOutput heading levels under a baseLevel band

Louis Deconinck765d123dd327
diff --git a/client/src/components/cos/MarkdownOutput.jsx b/client/src/components/cos/MarkdownOutput.jsx
index dd2f59bb2e..feec9b69a6 100644
--- a/client/src/components/cos/MarkdownOutput.jsx
+++ b/client/src/components/cos/MarkdownOutput.jsx
@@ -60,7 +60,7 @@ const H_STYLES = [
'text-xs font-semibold text-gray-300 mt-2 mb-0.5',
];
-function parseBlocks(md) {
+function parseBlocks(md, baseLevel) {
const lines = (md || '').split('\n');
const blocks = [];
let i = 0;
@@ -77,10 +77,12 @@ function parseBlocks(md) {
i = end + 1; continue;
}
- // Heading
+ // Heading — clamped into a band below the host card's own heading so
+ // embedded markdown never outranks the page outline (#7264). H_STYLES stays
+ // indexed by the source `#` count: only the tag name shifts, never the look.
const hm = line.match(/^(#{1,6})\s+(.*)/);
if (hm) {
- const Tag = `h${hm[1].length}`;
+ const Tag = `h${Math.min(6, baseLevel + hm[1].length - 1)}`;
blocks.push(<Tag key={i} className={H_STYLES[hm[1].length - 1]}>{parseInline(hm[2])}</Tag>);
i++; continue;
}
@@ -149,10 +151,10 @@ function parseBlocks(md) {
return blocks;
}
-export default function MarkdownOutput({ content }) {
+export default function MarkdownOutput({ content, baseLevel = 3 }) {
return (
<div className="markdown-output min-w-0 overflow-hidden break-words">
- {parseBlocks(content)}
+ {parseBlocks(content, baseLevel)}
</div>
);
}
diff --git a/client/src/components/cos/MarkdownOutput.test.jsx b/client/src/components/cos/MarkdownOutput.test.jsx
index 9cf81ae490..458f2542b8 100644
--- a/client/src/components/cos/MarkdownOutput.test.jsx
+++ b/client/src/components/cos/MarkdownOutput.test.jsx
@@ -1,4 +1,4 @@
-import { it, expect } from 'vitest';
+import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import MarkdownOutput from './MarkdownOutput';
@@ -13,3 +13,65 @@ it('still renders a genuine word-boundary _emphasis_ span as italic', () => {
expect(em.tagName).toBe('EM');
expect(screen.getByText(/this is/)).toBeInTheDocument();
});
+
+// MarkdownOutput renders inside cards, drawers and tab panels — never as the
+// page's own outline — so a `#` line in stored model output must not emit a
+// real `h1`/`h2` (#7264). Source levels shift into a band under `baseLevel`
+// (default 3) while H_STYLES keeps indexing the SOURCE `#` count, so only the
+// tag name moves; the in-card visual hierarchy is unchanged.
+
+const SOURCE_STYLES = {
+ 1: 'text-base font-bold text-white mt-3 mb-1',
+ 2: 'text-sm font-bold text-white mt-3 mb-1',
+ 3: 'text-xs font-semibold text-port-accent mt-2 mb-1',
+ 4: 'text-xs font-semibold text-gray-300 mt-2 mb-0.5',
+};
+
+describe('MarkdownOutput heading levels', () => {
+ it('shifts # to h3 at the default baseLevel', () => {
+ render(<MarkdownOutput content={'# Title'} />);
+ const heading = screen.getByRole('heading', { level: 3, name: 'Title' });
+ expect(heading.tagName).toBe('H3');
+ });
+
+ it('shifts ## and ### to h4 and h5', () => {
+ render(<MarkdownOutput content={'## Sub\n\n### Detail'} />);
+ expect(screen.getByRole('heading', { level: 4, name: 'Sub' }).tagName).toBe('H4');
+ expect(screen.getByRole('heading', { level: 5, name: 'Detail' }).tagName).toBe('H5');
+ });
+
+ it('shifts #### to h6', () => {
+ render(<MarkdownOutput content={'#### Deep'} />);
+ expect(screen.getByRole('heading', { level: 6, name: 'Deep' }).tagName).toBe('H6');
+ });
+
+ it('clamps ##### and ###### at h6 instead of emitting an invalid tag', () => {
+ const { container } = render(<MarkdownOutput content={'##### Five\n\n###### Six'} />);
+ expect(screen.getByRole('heading', { level: 6, name: 'Five' }).tagName).toBe('H6');
+ expect(screen.getByRole('heading', { level: 6, name: 'Six' }).tagName).toBe('H6');
+ expect(container.querySelector('h7')).toBeNull();
+ });
+
+ it('never emits h1 or h2 at the default baseLevel', () => {
+ const { container } = render(
+ <MarkdownOutput content={'# A\n\n## B\n\n### C\n\n#### D\n\n##### E\n\n###### F'} />,
+ );
+ expect(container.querySelector('h1, h2')).toBeNull();
+ });
+
+ it('keeps H_STYLES indexed by the source # count, not the emitted tag', () => {
+ render(<MarkdownOutput content={'# One\n\n## Two\n\n### Three\n\n#### Four'} />);
+ expect(screen.getByRole('heading', { level: 3, name: 'One' }).className).toBe(SOURCE_STYLES[1]);
+ expect(screen.getByRole('heading', { level: 4, name: 'Two' }).className).toBe(SOURCE_STYLES[2]);
+ expect(screen.getByRole('heading', { level: 5, name: 'Three' }).className).toBe(SOURCE_STYLES[3]);
+ expect(screen.getByRole('heading', { level: 6, name: 'Four' }).className).toBe(SOURCE_STYLES[4]);
+ });
+
+ it('shifts the whole band when a consumer passes baseLevel', () => {
+ render(<MarkdownOutput content={'# One\n\n## Two\n\n### Three'} baseLevel={4} />);
+ expect(screen.getByRole('heading', { level: 4, name: 'One' }).tagName).toBe('H4');
+ expect(screen.getByRole('heading', { level: 5, name: 'Two' }).tagName).toBe('H5');
+ // baseLevel 4 + source 3 - 1 = 6 — already at the ceiling.
+ expect(screen.getByRole('heading', { level: 6, name: 'Three' }).tagName).toBe('H6');
+ });
+});