Interface PreviewHandler

A PreviewHandler manages the integration of one or more previews.

It indicates whether a preview shall be rendered for a given resource URI and, if yes, renders the content. Additionally it optionally provides methods with which the scroll state of the preview and corresponding editor can be managed.

See MarkdownPreviewHandler for an example implementation.

interface PreviewHandler {
    iconClass?: string;
    canHandle(uri): number;
    findElementForFragment?(content, fragment): undefined | HTMLElement;
    findElementForSourceLine?(content, sourceLine): undefined | HTMLElement;
    getSourceLineForOffset?(content, offset): undefined | number;
    renderContent(params): MaybePromise<undefined | HTMLElement>;
}

Implemented by

Properties

iconClass?: string

One or more classes which specify the preview widget icon.

Methods

  • Indicates whether and with which priority (larger is better) this preview handler is responsible for the resource identified by the given URI. If multiple handlers return the same priority it's undefined which one will be used.

    Parameters

    • uri: URI

      the URI identifying a resource.

    Returns number

    a number larger than 0 if the handler is applicable, 0 or a negative number otherwise.

  • Search and return the HTMLElement which corresponds to the given fragment. This is used to initially reveal elements identified via the URI fragment.

    Parameters

    • content: HTMLElement

      the preview widget element containing the content previously rendered by PreviewHandler.renderContent.

    • fragment: string

      the URI fragment for which the corresponding element shall be returned

    Returns undefined | HTMLElement

    the HTMLElement which is part of content and corresponds to the given fragment, undefined otherwise.

  • Search and return the HTMLElement which corresponds to the given line number. This is used to scroll the preview when the source editor scrolls.

    Parameters

    • content: HTMLElement

      the preview widget element containing the previously rendered by PreviewHandler.renderContent.

    • sourceLine: number

      the line number for which the corresponding element shall be returned.

    Returns undefined | HTMLElement

    the HTMLElement which is part of content and corresponds to the given line number, undefined otherwise.

  • Returns the line number which corresponds to the preview element at the given offset. This is used to scroll the source editor when the preview scrolls.

    Parameters

    • content: HTMLElement

      the preview widget element containing the previously rendered by PreviewHandler.renderContent.

    • offset: number

      the total amount by which the preview widget is scrolled.

    Returns undefined | number

    the source line number which corresponds to the preview element at the given offset, undefined otherwise.

  • Render the preview content by returning appropriate HTML.

    Parameters

    Returns MaybePromise<undefined | HTMLElement>

    the HTMLElement which will be attached to the preview widget.