Some parts of this article have been written with AI. Be aware that AI can make mistakes.
Applies to : PowerDocs for Linux PowerDocs for Windows

Class `ExtensionContext`

The ExtensionContext object represents the root environment and API registry passed into an extension's activate(context) function. It acts as the gateway to interact with PowerDocs Markdown rendering, editor actions, and host system services.


Properties

Property Type Description
markdown Markdown Provides methods to declare custom Markdown blocks, syntax aliases, and custom PDF rendering engines.
editor EditorApi Provides methods to register contextual action items on text selection in the editor.
templates TemplatesApi Provides methods to register Markdown document templates available in File and Insert menus.
pipeline PipelineApi Provides hooks to intercept, inspect, and transform the document before PDF export or file saving.
env Env Provides system utilities such as clipboard manipulation, external URL opening, and application logging.
manifest object Contains the parsed manifest properties from the extension's extension.json file.

Methods

The ExtensionContext class is a composite host container and does not expose direct methods. Use its properties (context.markdown, context.editor, context.templates, context.pipeline, context.env) to interact with specific subsystems.


Code Examples

Complete Extension Lifecycle

export function activate(context) {
    context.env.log(`Activating extension: ${context.manifest.name} (v${context.manifest.version})`);

    // 1. Declare a custom container block ::: alert ... :::
    context.markdown.registerBlock({
        name: 'alert',
        aliases: ['warning', 'attention'],
        renderPdf: (renderer, content, args) => {
            renderer.box({
                backgroundColor: '#fffbeb',
                borderColor: '#f59e0b',
                borderLeftWidth: 4,
                cornerRadius: 4,
                padding: 8
            }, (box) => {
                box.text({ text: `⚠ ${args || 'WARNING'}`, bold: true, color: '#b45309', fontSize: 10.5 });
                box.text({ text: (content || '').trim(), color: '#78350f', fontSize: 9.5 });
            });
        }
    });

    // 2. Register an editor selection tool
    context.editor.registerSelectionAction({
        id: 'search-mdn',
        title: 'Search on MDN',
        icon: 'Globe',
        execute: (selection) => {
            const query = encodeURIComponent(selection.text.trim());
            context.env.openUrl(`https://developer.mozilla.org/search?q=${query}`);
        }
    });
}