Skip to content
lsdocs plugin SDK API

@lsdocs/plugin #

interface Span #

interface Span

A byte range in the source text (end exclusive).

property start #

start: number

property end #

end: number

type alias Node #

type Node = | ({ type: 'section'; id?: string } & Parent)
  | ({ type: 'heading'; level: number; id?: string } & Parent)
  | ({ type: 'paragraph' } & Parent)
  | ({ type: 'list'; ordered?: boolean; start?: number } & Parent)
  | ({ type: 'list_item'; checked?: boolean } & Parent)
  | ({ type: 'block_quote' } & Parent)
  | ({ type: 'code_block'; language?: string; info?: string; value: string } & NodeBase)
  | ({ type: 'table'; align?: Array<'none' | 'left' | 'center' | 'right'> } & Parent)
  | ({ type: 'table_row'; header?: boolean } & Parent)
  | ({ type: 'table_cell' } & Parent)
  | ({ type: 'thematic_break' } & NodeBase)
  | ({ type: 'raw'; format: string; value: string } & NodeBase)
  | ({ type: 'text'; value: string } & NodeBase)
  | ({ type: 'emphasis' } & Parent)
  | ({ type: 'strong' } & Parent)
  | ({ type: 'inline_code'; value: string } & NodeBase)
  | ({ type: 'link'; url: string; title?: string; target?: LinkTarget } & Parent)
  | ({ type: 'image'; url: string; alt?: string; title?: string } & NodeBase)
  | ({ type: 'line_break' } & NodeBase)
  | ({ type: 'admonition'; kind: string; title?: string } & Parent)
  | ({ type: 'definition_list' } & Parent)
  | ({ type: 'definition_term' } & Parent)
  | ({ type: 'definition_description' } & Parent)
  | ({ type: 'footnote_reference'; label: string } & NodeBase)
  | ({ type: 'footnote_definition'; label: string } & Parent)
  | ({ type: 'math'; value: string; display?: boolean } & NodeBase)
  | ({ type: 'figure'; id?: string } & Parent)
  | ({ type: 'caption' } & Parent)
  | ({ type: 'anchor'; id: string } & NodeBase)
  | ({ type: 'custom'; kind: string; attrs?: Record<string, unknown> } & Parent)

A node in the document tree, tagged by type.

interface LinkTarget #

interface LinkTarget

Where a cross-reference link points inside the site: a document (source path) and/or an anchor, or an unresolved label.

property document #

document?: string

property anchor #

anchor?: string

property label #

label?: string

interface Document #

interface Document

A parsed source document.

property source #

source: string

property metadata #

metadata?: Record<string, unknown>

property children #

children: Node[]

interface Diagnostic #

interface Diagnostic

property severity #

severity: 'error' | 'warning' | 'info' | 'hint'

property message #

message: string

property source #

source?: string

property span #

span?: Span

property code #

code?: string

interface ProjectInfo #

interface ProjectInfo

The project being built.

property root #

root?: string

Absolute path of the project directory; resolve option paths against it.

property source_dir #

source_dir?: string

Absolute path of the source directory, which document sources are relative to.

property files #

files?: string[]

Every source file (documents and assets), relative to the source directory, sorted.

interface SiteInfo #

interface SiteInfo

The site the project renders to.

property title #

title?: string

property base_url #

base_url?: string

interface Context #

interface Context

What a handler receives alongside its params.

property project #

readonly project: ProjectInfo

property site #

readonly site: SiteInfo

property settings #

readonly settings: Record<string, string | null> | null

The plugin's settings: each of its configFiles ({name} resolved) mapped to its text, or null if missing.

property config #

readonly config: { dir: string; name: string }

dir (the project's .config/) and name (the plugin's name in the project config).

method log #

log(level: 'error' | 'warn' | 'info' | 'debug' | 'trace', message: string): void

method debug #

debug(message: string): void

method info #

info(message: string): void

method warn #

warn(message: string): void

method progress #

progress(message: string, percentage?: number): void

method diagnostic #

diagnostic(diagnostic: Diagnostic): void

interface ParseParams #

interface ParseParams

property source #

source: string

property text #

text: string

property fragment #

fragment?: { context?: 'block' | 'inline' }

Present when text is a piece of a document: return its nodes as document.children.

property origin #

origin?: { source: string; offset?: number }

Where text really comes from, for diagnostics: its file and byte offset in it.

interface ParseResult #

interface ParseResult

property document #

document: Document

property diagnostics #

diagnostics?: Diagnostic[]

interface ReadParams #

interface ReadParams

property document #

document: Document

interface ReadResult #

interface ReadResult

property data #

data: unknown

property diagnostics #

diagnostics?: Diagnostic[]

interface ApplyParams #

interface ApplyParams

property document #

document: Document

property collected #

collected: Record<string, unknown> | null

Collected data from every document, keyed by source; null without parse/transform/each.

interface ApplyResult #

interface ApplyResult

property document #

document: Document

property diagnostics #

diagnostics?: Diagnostic[]

interface RenderParams #

interface RenderParams

property document #

document: Document

property format #

format: string

interface RenderResult #

interface RenderResult

property output #

output: string | Uint8Array

property extension #

extension?: string

property diagnostics #

diagnostics?: Diagnostic[]

property data #

data?: unknown

Data about the page, handed back in renderAll's pages (cached with the page).

interface RenderedPage #

interface RenderedPage

A page written by the render phase.

property source #

source: string

property path #

path: string

Output path, relative to the output directory.

property metadata #

metadata?: Record<string, unknown>

property data #

data?: unknown

The data its render returned, if any.

interface RenderAllParams #

interface RenderAllParams

property format #

format: string

property pages #

pages: RenderedPage[]

interface OutputFile #

interface OutputFile

A file no single page makes, to write, e.g. a sitemap.

property path #

path: string

property output #

output: string | Uint8Array

interface RenderAllResult #

interface RenderAllResult

property files #

files?: OutputFile[]

property diagnostics #

diagnostics?: Diagnostic[]

interface PluginDefinition #

interface PluginDefinition

A plugin's definition. Each phase is optional.

property name #

name: string

property version #

version?: string

property maxConcurrency #

maxConcurrency?: number

Requests handled at once (default 1).

property configFiles #

configFiles?: string[]

The files the plugin reads its settings from, relative to .config/, {name} standing for its name in the site config (lsdocs' own plugins use lsdocs/{name}/settings.toml). Read when the session starts.

property parse #

parse?: { extensions: string[]; handler: Handler<ParseParams, ParseResult | Document> }

property read #

read?: | Handler<ReadParams, ReadResult | unknown> | { handler: Handler<ReadParams, ReadResult | unknown> }

property transform #

transform?: | Handler<ApplyParams, ApplyResult | Document> | { nodes?: string[]; handler: Handler<ApplyParams, ApplyResult | Document> }

property render #

render?: { formats: string[] handler: Handler<RenderParams, RenderResult | string | Uint8Array> }

property renderAll #

renderAll?: | Handler<RenderAllParams, RenderAllResult | OutputFile[]> | { handler: Handler<RenderAllParams, RenderAllResult | OutputFile[]> }

Called once after every page is rendered; returns files no single page makes (or just the list of them). Needs render.

interface Capabilities #

interface Capabilities

property parse #

parse?: { extensions: string[] }

property transform #

transform?: { nodes?: string[]; each: boolean }

property render #

render?: { formats: string[]; all?: boolean }

property max_concurrency #

max_concurrency?: number

property cache #

cache?: string

class Plugin #

class Plugin

constructor constructor #

constructor(definition: PluginDefinition)

field name #

readonly name: string

field version #

readonly version: string

field capabilities #

readonly capabilities: Capabilities

method serve #

serve(): Promise<void>

Runs the plugin until the host is done with it.

function definePlugin #

function definePlugin(definition: PluginDefinition): Plugin

constant PROTOCOL_VERSION #

const PROTOCOL_VERSION: string

Protocol version spoken by this package.