twoslash-python
Version:
Twoslash generator for Python - Enhance your Python documentation with TypeScript-like type information
178 lines • 5.55 kB
TypeScript
import type { ShikiTransformerContextCommon } from '@shikijs/types';
import type { Element, ElementContent, Text } from 'hast';
import type { TwoslashRenderer } from '@shikijs/twoslash/core';
export interface RendererRichOptionsPython {
/**
* Custom icons for completion items.
* A map from completion item kind to a HAST node.
*
* If `false`, no icons will be rendered.
* @default defaultCompletionIcons
*/
completionIcons?: Partial<Record<string, ElementContent>> | false;
/**
* Custom icons for custom tags lines.
* A map from tag name to a HAST node.
*
* If `false`, no icons will be rendered.
* @default defaultCustomTagIcons
*/
customTagIcons?: Partial<Record<string, ElementContent>> | false;
/**
* Custom formatter for the type info text.
* Note that it might not be valid TypeScript syntax.
*
* @default defaultHoverInfoProcessor
*/
processHoverInfo?: (info: string) => string;
/**
* Custom formatter for the docs text (can be markdown).
*
* @default undefined
*/
processHoverDocs?: (docs: string) => string;
/**
* The way errors should be rendered.
*
* - `'line'`: Render the error line after the line of code
* - `'hover'`: Render the error in the hover popup
*
* @default 'line'
*/
errorRendering?: 'line' | 'hover';
/**
* Classes added to injected elements
*/
classExtra?: string;
/**
* Language for syntax highlight.
* @default the language of the code block
*/
lang?: string;
/**
* Custom function to render markdown.
*
* By default it pass-through the markdown.
*/
renderMarkdown?: (this: ShikiTransformerContextCommon, markdown: string) => ElementContent[];
/**
* Custom function to render inline markdown.
*
* By default it pass-through the markdown.
*/
renderMarkdownInline?: (this: ShikiTransformerContextCommon, markdown: string, context: string) => ElementContent[];
/**
* The way query should be rendered.
* - `'popup'`: Render the query in the absolute popup
* - `'line'`: Render the query line after the line of code
* @default 'popup'
*/
queryRendering?: 'popup' | 'line';
/**
* Extensions for the genreated HAST tree.
*/
hast?: {
/**
* The <code> block for in the hover popup.
*/
popupTypes?: HastExtension;
/**
* The documentation block in the hover popup. Can be markdown rendered if `renderMarkdown` is provided.
*/
popupDocs?: HastExtension;
/**
* The container of jsdoc tags in the hover popup.
*/
popupDocsTags?: HastExtension;
/**
* The token for the hover informaton.
*/
hoverToken?: HastExtension;
/**
* The container of the hover popup.
*/
hoverPopup?: HastExtension;
/**
* The container of error popup.
*/
popupError?: HastExtension;
/**
* Custom function to compose the hover token.
*/
hoverCompose?: (parts: {
popup: Element;
token: Text | Element;
}) => ElementContent[];
/**
* The token for the query informaton.
*/
queryToken?: HastExtension;
/**
* The container of the query popup.
*/
queryPopup?: HastExtension;
/**
* Custom function to compose the hover token.
*/
queryCompose?: (parts: {
popup: Element;
token: Text | Element;
}) => ElementContent[];
/**
* The token for the completion informaton.
*/
completionToken?: HastExtension;
/**
* The cursor element in the completion popup.
*/
completionCursor?: HastExtension;
/**
* The container of the completion popup.
*/
completionPopup?: HastExtension;
/**
* Custom function to compose the completion token.
*/
completionCompose?: (parts: {
popup: Element;
cursor: Element;
}) => ElementContent[];
/**
* The token for the error informaton.
*/
errorToken?: HastExtension;
/**
* The container of the error popup.
* Only used when `errorRendering` is set to `'hover'`.
*/
errorPopup?: HastExtension;
/**
* Custom function to compose the error token.
* Only used when `errorRendering` is set to `'hover'`.
*/
errorCompose?: (parts: {
popup: Element;
token: Text | Element;
}) => ElementContent[];
/**
* The wrapper for the highlighted nodes.
*/
nodesHighlight?: HastExtension;
};
}
export interface HastExtension {
tagName?: string;
properties?: Element['properties'];
class?: string;
children?: (input: ElementContent[]) => ElementContent[];
}
/**
* An alternative renderer that providers better prefixed class names,
* with syntax highlight for the info text.
*/
export declare function rendererRichPython(options?: RendererRichOptionsPython): TwoslashRenderer;
/**
* The default hover info processor, which will do some basic cleanup
*/
export declare function defaultHoverInfoProcessor(type: string): string;
//# sourceMappingURL=renderer.d.ts.map