Applies to :
PowerDocs for Linux
PowerDocs for Windows
Class `Markdown`
The Markdown class (accessed via context.markdown) allows extensions to declare custom Markdown block containers and
customize their visual rendering in generated PDF documents and previews.
Properties
Markdown does not expose public properties.
Methods
registerBlock(descriptor)
Registers a custom Markdown block type with its associated PDF renderer and aliases.
Parameters
descriptor(object): A configuration object describing the custom block.
| Field | Type | Required | Description |
|---|---|---|---|
name |
string |
Yes | The primary tag name of the block (e.g., 'swagger', 'DO', 'tip'). |
aliases |
string[] |
No | Alternative tag names recognized for this block (e.g., ['endpoint', 'api']). |
renderPdf |
function(renderer, content, args) |
No | Callback invoked when rendering the block to PDF via QuestPDF. |
renderEditor |
function(editor, content) |
No | Reserved for future interactive canvas rendering in the editor. |
Callback Parameters for renderPdf(renderer, content, args)
renderer(PdfRenderer): Fluent layout builder for constructing PDF components (boxes, columns, rows, badges, text, code, lines).content(string): The text content inside the block body.args(string): Any parameters or arguments passed on the first declaration line (e.g. for::: swagger GET /api/v1/users,argsis"GET /api/v1/users").
Examples
1. Declaring a Recommendation Block (::: DO / ::: DONT)
export function activate(context) {
// Green DO block
context.markdown.registerBlock({
name: 'DO',
aliases: ['do', 'recommendation', 'good-practice'],
renderPdf: (renderer, content, args) => {
const title = (args || '').trim();
const body = (content || '').trim();
renderer.box({
backgroundColor: '#ecfdf5',
borderColor: '#10b981',
borderLeftWidth: 4,
cornerRadius: 4,
padding: 8,
marginTop: 6,
marginBottom: 6
}, (box) => {
const header = title.length > 0 ? `DO: ${title}` : 'DO (Recommended)';
box.text({text: header, bold: true, color: '#047857', fontSize: 10.5});
if (body.length > 0) {
box.text({text: body, color: '#065f46', fontSize: 9.5});
}
});
}
});
}
2. Declaring a REST API Endpoint Block (::: swagger)
export function activate(context) {
context.markdown.registerBlock({
name: 'swagger',
aliases: ['SwaggerEndpoint', 'endpoint', 'api'],
renderPdf: (renderer, content, args) => {
const rawArgs = (args || '').trim();
const rawContent = (content || '').trim();
let method = 'GET';
let path = '/';
let description = rawContent;
if (rawArgs.length > 0) {
const parts = rawArgs.split(' ');
if (parts.length >= 2) {
method = parts[0].toUpperCase();
path = parts.slice(1).join(' ');
} else {
path = rawArgs;
}
}
const methodColors = {
'GET': {bg: '#f0f9ff', border: '#38bdf8', badge: '#0284c7'},
'POST': {bg: '#f0fdf4', border: '#4ade80', badge: '#16a34a'},
'PUT': {bg: '#fffbeb', border: '#fcd34d', badge: '#d97706'},
'DELETE': {bg: '#fef2f2', border: '#f87171', badge: '#dc2626'}
};
const theme = methodColors[method] || methodColors['GET'];
renderer.box({
backgroundColor: theme.bg,
borderColor: theme.border,
borderLeftWidth: 4,
cornerRadius: 4,
padding: 8,
marginTop: 6,
marginBottom: 6
}, (box) => {
box.row((row) => {
row.badge({text: method, backgroundColor: theme.badge, textColor: '#ffffff', bold: true});
row.text({text: ' ' + path, bold: true, color: '#0f172a', fontSize: 10});
});
if (description.length > 0) {
box.line({color: theme.border, thickness: 0.5, marginVertical: 6});
box.text({text: description, fontSize: 9.5, color: '#334155'});
}
});
}
});
}
3. Usage in Markdown
Users can now write either:
::: swagger GET /api/v1/orders Fetches the list of all customer orders.
:::
::: DO Always Validate Input Ensure all request payload parameters are strictly validated against schema models.
:::