import { ChatResponsePartRenderer } from '../chat-response-part-renderer.js';
import { ChatResponseContent, InformationalChatResponseContent, MarkdownChatResponseContent } from '@theia/ai-chat/lib/common';
import { ReactNode } from '@theia/core/shared/react';
import * as React from '@theia/core/shared/react';
import markdownit from '@theia/core/shared/markdown-it';
import { MarkdownString } from '@theia/core/lib/common/markdown-rendering';
import { OpenerService } from '@theia/core/lib/browser';
export interface MarkdownRenderProps {
text: string | MarkdownString;
openerService: OpenerService;
className?: string;
}
/**
* Renders the given markdown via {@link useMarkdownRendering} into a `
`.
* Shared component for use across chat response renderers.
*/
export declare const MarkdownRender: React.FC;
export declare class MarkdownPartRenderer implements ChatResponsePartRenderer {
protected readonly openerService: OpenerService;
protected readonly markdownIt: markdownit;
canHandle(response: ChatResponseContent): number;
render(response: MarkdownChatResponseContent | InformationalChatResponseContent): ReactNode;
}
export declare namespace MarkdownRendering {
/**
* Renders markdown into a detached fragment, exactly as {@link useMarkdownRendering} does before mounting it.
* Also used to read the rendered text of markdown that is not mounted, e.g. to search a chat session.
*/
function renderToFragment(markdown: string, skipSurroundingParagraph?: boolean, blockExternalResourceLoading?: boolean): DocumentFragment;
/** Prepares the text of a chat request text part for inline rendering. */
function prepareRequestText(text: string): string;
}
export interface DeclaredEventsEventListenerObject extends EventListenerObject {
handledEvents?: (keyof HTMLElementEventMap)[];
}
/**
* This hook uses markdown-it directly to render markdown.
* The reason to use markdown-it directly is that the MarkdownRenderer is
* overridden by theia with a monaco version. This monaco version strips all html
* tags from the markdown with empty content. This leads to unexpected behavior when
* rendering markdown with html tags.
*
* Moreover, we want to intercept link clicks to use the Theia OpenerService instead of the default browser behavior.
*
* @param markdown the string to render as markdown
* @param skipSurroundingParagraph whether to remove a surrounding paragraph element (default: false)
* @param openerService the service to handle link opening
* @param eventHandler `handleEvent` will be called by default for `click` events and additionally
* for all events enumerated in {@link DeclaredEventsEventListenerObject.handledEvents}. If `handleEvent` returns `true`,
* no additional handlers will be run for the event.
* @param blockExternalResourceLoading whether external URL resources should be blocked until explicitly allowed (default: true).
* Trusted content authored by the user (e.g. their own chat requests) can pass `false` to render such resources directly.
* Active embedded content (iframes, frames, objects, embeds) is always blocked regardless of this flag.
* @returns the ref to use in an element to render the markdown
*/
export declare const useMarkdownRendering: (markdown: string | MarkdownString, openerService: OpenerService, skipSurroundingParagraph?: boolean, eventHandler?: DeclaredEventsEventListenerObject, blockExternalResourceLoading?: boolean) => React.RefObject;
//# sourceMappingURL=markdown-part-renderer.d.ts.map