import React from 'react'; import { PROSE_BODY } from '@renderer/constants/cssVariables'; import { highlightSearchInChildren, type SearchContext } from './searchHighlightUtils'; import type { Components } from 'react-markdown'; /** * Create inline markdown components for rendering prose content. * When searchCtx is provided, search term highlighting is applied * to text nodes while preserving full markdown rendering. */ export function createMarkdownComponents(searchCtx: SearchContext | null): Components { const hl = (children: React.ReactNode): React.ReactNode => searchCtx ? highlightSearchInChildren(children, searchCtx) : children; return { // Headings - Bold text with generous spacing to break up content h1: ({ children }) => (
{hl(children)}
), // Links — inline element, no hl(); parent block element's hl() descends here a: ({ href, children }) => ( {children} ), // Strong/Bold — inline element, no hl() strong: ({ children }) => ( {children} ), // Emphasis/Italic — inline element, no hl() em: ({ children }) => ( {children} ), // Strikethrough — inline element, no hl() del: ({ children }) => (
{hl(children)}
);
}
// Inline code — no hl(); parent block element's hl() descends here
return (
{children}
);
},
// Code blocks
pre: ({ children }) => (
{children}
),
// Blockquotes
blockquote: ({ children }) => (
{hl(children)}), // Lists ul: ({ children }) => (