Files
paseo/packages/app/src/components/markdown/link-children.ts
T
Mohamed Boudra 23d7a8eaf9 Improve Markdown file preview readability (#3240)
* feat(app): improve markdown file previews

Keep rendered documents on the chat reading rail, surface YAML front matter as readable metadata, and make shared Markdown links retain the chat accent and hover treatment.

* fix(app): preserve unsafe frontmatter source

* test(app): cover markdown link behavior
2026-08-12 00:18:30 +02:00

22 lines
715 B
TypeScript

import { Children, cloneElement, isValidElement, type ReactNode } from "react";
import type { StyleProp, TextStyle } from "react-native";
export function colorMarkdownLinkChildren(
children: ReactNode,
color: TextStyle["color"],
): ReactNode {
return Children.map(children, (child) => {
if (!isValidElement<{ style?: StyleProp<TextStyle> }>(child)) return child;
return cloneElement(child, { style: [child.props.style, { color }] });
});
}
const MARKDOWN_LINK_HOVER_STYLE: TextStyle = { textDecorationLine: "underline" };
export function markdownLinkTextStyle(
style: StyleProp<TextStyle>,
hovered: boolean,
): StyleProp<TextStyle> {
return [style, hovered && MARKDOWN_LINK_HOVER_STYLE];
}