Applies to :
PowerDocs for Linux
PowerDocs for Windows
JavaScript Extensions Developer Guide
Welcome to the PowerDocs Extension Development Guide. PowerDocs allows developers to extend its capabilities using modern JavaScript scripts executed via the fast and sandboxed Jint JavaScript engine.
Overview
With PowerDocs Extensions, you can:
- Declare Custom Markdown Blocks: Render specialized Markdown containers (using the standard
::: blockName argssyntax) with rich custom PDF formatting (QuestPDF boxes, badges, columns, code blocks, borders, colors). - Add Selection Actions: Provide contextual actions that appear in the popup bar when users select text in the editor (e.g., web search, translation, text formatting, snippet generation).
- Interact with the System Environment: Open external web URLs, copy text to the system clipboard, and log diagnostic messages.
Extension Directory Structure
Extensions reside in the PowerDocs application data folder:
- Linux:
~/.local/share/PowerDocs/extensions/<extension-name>/ - Windows:
%APPDATA%\PowerDocs\extensions\<extension-name>\ - macOS:
~/Library/Application Support/PowerDocs/extensions/<extension-name>/
Each extension is a separate folder containing at minimum:
my-custom-extension/
├── extension.json # Extension manifest
└── index.js # Entry point script
Extension Manifest (extension.json)
The extension.json file describes your extension metadata:
{
"id": "com.company.myextension",
"name": "My Custom Extension",
"version": "1.0.0",
"description": "Adds custom Markdown blocks and editor selection tools.",
"author": "Developer Name",
"main": "index.js"
}
Manifest Fields
| Field | Type | Required | Description |
|---|---|---|---|
id |
string |
Yes | Unique identifier for your extension (e.g. com.example.swagger). |
name |
string |
Yes | Human-readable name of the extension. |
version |
string |
Yes | Semantic version string (e.g. 1.0.0). |
description |
string |
No | Short description of what the extension does. |
author |
string |
No | Author or organization name. |
main |
string |
No | Path to the entry point script (defaults to index.js). |
Extension Entry Point (index.js)
Each extension must export an activate(context) function. PowerDocs invokes this function upon application startup or when extensions are reloaded.
export function activate(context) {
// Register custom Markdown blocks
context.markdown.registerBlock({
name: 'note',
renderPdf: (renderer, content, args) => {
renderer.box({
backgroundColor: '#eff6ff',
borderColor: '#3b82f6',
borderLeftWidth: 4,
padding: 8
}, (box) => {
box.text({ text: args || 'NOTE', bold: true, color: '#1d4ed8' });
box.text({ text: (content || '').trim(), color: '#1e3a8a' });
});
}
});
// Register selection tools
context.editor.registerSelectionAction({
id: 'uppercase-action',
title: 'UPPERCASE',
icon: 'TextCaseUppercase',
execute: (selection) => {
selection.replaceText(selection.text.toUpperCase());
}
});
}
API Reference
Explore the individual API class documentation:
ExtensionContext: Root context object passed toactivate(context).Markdown: Register custom Markdown block containers and PDF renderers (context.markdown).Editor: Register contextual actions on text selection (context.editor).SelectionContext: Object passed to selection action callbacks (selection.text,replaceText,insertText).Templates: Register document templates and snippets (context.templates).Pipeline: Pre-processing hooks before PDF export and save (context.pipeline).DocumentDom: Structured Document Object Model (JsDocument,find,findText,replaceText).PdfRenderer: Fluent QuestPDF layout builder API (box,row,column,badge,text,line,code).EnvApi: System interaction utilities (openUrl,setClipboard,logInfo).