Files
opencode-manager/frontend/src/components/ui/markdown-link.tsx
T
Chris Scott 7fbb7555b2 feat(files): fullscreen preview, relative markdown links, and preinstalled Chromium (#369)
* feat(files): add fullscreen preview with a minimal close control

Add a fullscreen toggle to the desktop file preview header. Fullscreen fills the viewport, hides the header, and shows only a small on-top X to exit.

Keep the mobile preview fullscreen by default with its close button layered above the content, and give the headerless mobile preview the same small on-top X.

* fix(files): open relative markdown links and preinstall Chromium

Resolve relative and absolute markdown links against the previewed file
and open them in the file browser; external links open in a new tab.
Install Playwright and Chromium into the Manager image with NODE_PATH
and PLAYWRIGHT_BROWSERS_PATH so agents can run browser automation
without a project-local install.

* refactor(files): share markdown link handling across renderers

* test(docker): cover the preinstalled playwright chromium step
2026-09-29 00:15:52 -04:00

38 lines
1.1 KiB
TypeScript

import type { ComponentPropsWithoutRef } from 'react'
import type { ExtraProps } from 'react-markdown'
import { getLocalLinkPath, isExternalLink } from '@/lib/markdownLinks'
type MarkdownLinkProps = ComponentPropsWithoutRef<'a'> & ExtraProps & {
onOpenLocalPath?: (linkPath: string) => void
}
/**
* Renders a markdown link. Local file links call `onOpenLocalPath` instead of navigating the app,
* and external http(s) links open in a new tab.
*/
export function MarkdownLink({ href, children, onOpenLocalPath, ...rest }: MarkdownLinkProps) {
delete (rest as Record<string, unknown>).node
const localPath = onOpenLocalPath ? getLocalLinkPath(href) : null
if (localPath && onOpenLocalPath) {
return (
<a
href={href}
{...rest}
onClick={(event) => {
event.preventDefault()
onOpenLocalPath(localPath)
}}
>
{children}
</a>
)
}
if (isExternalLink(href)) {
return <a href={href} target="_blank" rel="noopener noreferrer" {...rest}>{children}</a>
}
return <a href={href} {...rest}>{children}</a>
}