Skip to content
lsdocs-rst API

@lsdocs/rst #

interface Span #

interface Span

Byte offsets in the parsed text: start inclusive, end exclusive.

property start #

start: number

property end #

end: number

type alias AttrValue #

type AttrValue = string | string[] | number | boolean | null

An attribute value.

interface Element #

interface Element

An element: a docutils node kind ("paragraph", "section", ...).

property kind #

kind: string

property attributes #

attributes?: Record<string, AttrValue>

property children #

children?: Node[]

property span #

span?: Span

interface Text #

interface Text

Text in the tree.

property text #

text: string

property span #

span?: Span

type alias Node #

type Node = Element | Text

interface Settings #

interface Settings

The docutils settings the parser honors, by their docutils names.

property doctitle_xform #

doctitle_xform?: boolean

property docinfo_xform #

docinfo_xform?: boolean

property sectsubtitle_xform #

sectsubtitle_xform?: boolean

property sectnum_xform #

sectnum_xform?: boolean

property title #

title?: string | null

property tab_width #

tab_width?: number

property line_length_limit #

line_length_limit?: number

property raw_enabled #

raw_enabled?: boolean

property pep_references #

pep_references?: boolean

property pep_base_url #

pep_base_url?: string

property pep_file_url_template #

pep_file_url_template?: string

property rfc_references #

rfc_references?: boolean

property rfc_base_url #

rfc_base_url?: string

property trim_footnote_reference_space #

trim_footnote_reference_space?: boolean

property id_prefix #

id_prefix?: string

property auto_id_prefix #

auto_id_prefix?: string

property strip_comments #

strip_comments?: boolean

property task_lists #

task_lists?: boolean

Task lists (- [ ] item, - [x] item); not a docutils setting. Off by default.

type alias OptionKind #

type OptionKind = | 'flag'
  | 'unchanged'
  | 'unchanged_required'
  | 'path'
  | 'uri'
  | 'int'
  | 'nonnegative_int'
  | 'percentage'
  | 'length_or_unitless'
  | 'length_or_percentage_or_unitless'
  | 'class_option'

docutils' option conversion functions, by name.

type alias OptionValue #

type OptionValue = string | number | string[] | null

A converted option value: null for flags.

interface DirectiveContext #

interface DirectiveContext

What a directive's run gets.

property name #

readonly name: string

The directive name as written.

property arguments #

readonly arguments: string[]

property options #

readonly options: Record<string, OptionValue>

property content #

readonly content: string[]

The content lines, indentation removed.

property lineno #

readonly lineno: number

The line number of the directive's first line.

property blockText #

readonly blockText: string

property span #

readonly span?: Span

property inSubstitution #

readonly inSubstitution: boolean

method parseContent #

parseContent(container: Element): Element

Parses the content as body elements into container.

method parseInline #

parseInline(text: string): [Node[], Element[]]

Parses text as inline markup: the nodes, and messages to put after their element.

method message #

message(level: number, text: string): Element

A system message (1 info to 4 severe) for the directive's line.

interface Directive #

interface Directive

A directive: what it accepts, and run.

property requiredArguments #

requiredArguments?: number

property optionalArguments #

optionalArguments?: number

property finalArgumentWhitespace #

finalArgumentWhitespace?: boolean

property optionSpec #

optionSpec?: Record<string, OptionKind | string[]>

Option names to conversion functions, or to lists of choices.

property hasContent #

hasContent?: boolean

method run #

run(ctx: DirectiveContext): Array<Node | string>

The directive's nodes; throw a DirectiveError to report a problem instead.

interface RoleContext #

interface RoleContext

What a role function gets.

property name #

readonly name: string

property text #

readonly text: string

The text, escapes removed.

property rawText #

readonly rawText: string

The text with its backslashes, as written.

property rawsource #

readonly rawsource: string

The whole interpreted text as written, role included.

property options #

readonly options: Record<string, OptionValue>

Options from the role directive that made the role.

property lineno #

readonly lineno: number

property span #

readonly span?: Span

type alias RoleFunction #

type RoleFunction = (ctx: RoleContext) => Array<Node | string>

type alias Loader #

type Loader = (path: string) => Uint8Array | string

Reads a file or URL: bytes, or a string (taken as UTF-8). Throw a Node.js system error (code such as ENOENT) for a failed read.

interface ParserOptions #

interface ParserOptions

property source #

source?: string

The document's name, used in messages.

property transforms #

transforms?: boolean

Apply docutils' transforms, as publish_doctree does.

property keepUnknownDirectives #

keepUnknownDirectives?: boolean

Keep unknown directives as directive elements instead of reporting them.

property settings #

settings?: Settings

property directives #

directives?: Record<string, Directive>

Directives by name, before any standard one of that name.

property roles #

roles?: Record<string, RoleFunction>

Role functions by name.

property root #

root?: string

Let directives read files below this directory.

property files #

files?: Loader

Or read files with this function.

property urls #

urls?: Loader

And URLs with this one.

interface ParseResult #

interface ParseResult

property document #

document: Element

property messages #

messages: Element[]

Messages docutils' transforms report outside the tree.

class DirectiveError #

class DirectiveError extends Error

Thrown by a directive or role: reported in the document as a system message.

constructor constructor #

constructor(message: string, level?: number)

field level #

readonly level: number

class Parser #

class Parser

constructor constructor #

constructor(options?: ParserOptions)

field settings #

readonly settings: Required<Settings>

The docutils settings in use.

method parse #

parse(text: string): Element

Parses text into a document element. Throws only when a JS directive, role or loader throws (other than DirectiveError and system errors).

method parseWithMessages #

parseWithMessages(text: string): ParseResult

constant INFO #

const INFO: 1

constant WARNING #

const WARNING: 2

constant ERROR #

const ERROR: 3

constant SEVERE #

const SEVERE: 4

function parse #

function parse(text: string, options?: ParserOptions): Element

function parseWithMessages #

function parseWithMessages(text: string, options?: ParserOptions): ParseResult

function pformat #

function pformat(node: Node): string

Pseudo-XML, exactly as docutils' pformat() prints it.

function toXml #

function toXml(element: Element, options?: { newlines?: boolean; indents?: boolean; xmlDeclaration?: boolean; doctypeDeclaration?: boolean }): string

Docutils XML, as docutils --writer=xml writes it.

function astext #

function astext(node: Node): string

function traverse #

function traverse(element: Element): Generator<Element>

This element and its descendant elements, in document order.

function findAll #

function findAll(element: Element, kind?: string): Element[]

This element and its descendants of kind (all if omitted).

function isElement #

function isElement(node: unknown): node is Element

function isText #

function isText(node: unknown): node is Text

function makeId #

function makeId(name: string): string

name as docutils makes ids of names.

function defaultSettings #

function defaultSettings(): Required<Settings>

The settings with docutils' defaults.