import { createContext, useContext, type ParentProps } from "solid-js" export type ReadMarkdownImage = (path: string, signal: AbortSignal) => Promise /** Open a local file path linked from markdown. The path is decoded and may be relative or absolute. */ export type OpenMarkdownLocalFile = (path: string) => void /** * Whether an inline-code path names a file that exists. Inline code is styled as a file link only when this says yes; * without it, inline code stays plain. */ export type MarkdownLocalFileExists = (path: string) => boolean | Promise const context = createContext<{ readonly readImage?: ReadMarkdownImage readonly openLocalFile?: OpenMarkdownLocalFile readonly localFileExists?: MarkdownLocalFileExists readonly openSession?: (sessionID: string) => void readonly sessionTitle?: (sessionID: string) => string | undefined }>() export function MarkdownProvider( props: ParentProps<{ readImage?: ReadMarkdownImage openLocalFile?: OpenMarkdownLocalFile localFileExists?: MarkdownLocalFileExists openSession?: (id: string) => void sessionTitle?: (id: string) => string | undefined }>, ) { const parent = useMarkdown() return ( {props.children} ) } export const useMarkdown = () => useContext(context) /** Provides markdown handlers as they are, e.g. the ones a detached view keeps while another Location is selected. */ export const MarkdownContext = context