/** * @template {string | any[]} [TContent=string] * @abstract */ export abstract class AbstractBlock extends AbstractNode { /** * @param {AbstractBlock} parent * @param {string} context * @param {object} [opts={}] */ constructor(parent: AbstractBlock, context: string, opts?: object); /** @type {string[]} */ subs: string[]; /** @type {string[]|null} */ defaultSubs: string[] | null; /** @type {string|number|null} */ numeral: string | number | null; /** @type {Cursor|null} */ sourceLocation: Cursor | null; /** * Describes the type of content this block accepts and how it should be converted. Acceptable values are: * - `compound` - this block contains other blocks * - `simple` - this block holds a paragraph of prose that receives normal substitutions * - `verbatim` - this block holds verbatim text (displayed "as is") that receives verbatim substitutions * - `raw` - this block holds unprocessed content passed directly to the output with no substitutions applied * - `empty` - this block has no content * @type {string} */ contentModel: string; /** * Array of {@link AbstractBlock} child blocks for this block. Only applies if content model is `compound`. * @type {AbstractBlock[]} */ blocks: AbstractBlock[]; style: string; level: number; /** * Set the String block title (clears the memoised converted title). * @param {string|null} val */ set title(val: string | null); /** * Get the String title of this block with title substitutions applied. * The result is pre-computed during Document.parse() via precomputeTitle(). * Falls back to applyHeaderSubs (sync) if precomputeTitle() has not been called yet * (e.g. when a title is set via the API after parsing). * @returns {string|null} the converted String title, or null if the source title is falsy. */ get title(): string | null; /** * Pre-compute the converted title asynchronously. * Called during Document.parse() so the synchronous getter works during conversion. * Re-entrant calls (circular title references) are detected via _computingTitle and * silently skipped so that {@link Section.xreftext()} can return null (→ "[refid]" fallback). * @returns {Promise} */ precomputeTitle(): Promise; _computingTitle: boolean; /** * Check whether the title of this block is defined. * @returns {boolean} */ hasTitle(): boolean; /** * Set the caption for this block. * @param {string|null} val */ set caption(val: string | null); /** * Get the caption for this block. * For admonition blocks, returns the 'textlabel' attribute instead. * @returns {string|null} */ get caption(): string | null; /** * Get the source file where this block started. * @returns {string|null} */ get file(): string | null; /** * Get the source line number where this block started. * @returns {number|null} */ get lineno(): number | null; /** * Update the context of this block, also updating the node name. * @param {string} context - The String context to assign to this block. */ setContext(context: string): void; /** * @deprecated * @param {number|string} val */ set number(val: number | string); /** * @deprecated Get/set the numeral of this section as an integer when possible. * @returns {number|string} */ get number(): number | string; /** * Convert this block and return the converted String content. * @returns {Promise} the result of the converter. */ convert(): Promise; /** @deprecated Use convert() instead. */ render(): Promise; /** * Get the converted result of all child blocks joined with a newline. * @returns {Promise} */ content(): Promise; /** * Alias for the content method — mirrors the core API. * @returns {Promise} */ getContent(): Promise; /** * Append a content block to this block's list of blocks. * @param {AbstractBlock} block - The new child block. * @returns {AbstractBlock} this block (enables chaining). */ append(block: AbstractBlock): AbstractBlock; /** * Determine whether this block contains block content. * @returns {boolean} */ hasBlocks(): boolean; /** * Check whether this block has any child Section objects. * Overridden by Document and Section. * @returns {boolean} */ hasSections(): boolean; /** * Get the child Section objects of this block. * Only applies to Document and Section instances. * @returns {AbstractBlock[]} array of Section objects (may be empty). */ sections(): AbstractBlock[]; /** * Get the converted alt text for this block image. * @returns {string} string with XML special character and replacement substitutions applied. */ alt(): string; /** * Get the converted alt text for this block image (alias of alt). * @returns {string} */ getAlt(): string; /** * Get the converted title prefixed with the caption. * @returns {string} the captioned title. */ captionedTitle(): string; /** * Get the list marker keyword for the specified list type. * @param {string|null} [listType=null] - The String list type (default: this.style). * @returns {string|undefined} the single-character String keyword for the list marker. */ listMarkerKeyword(listType?: string | null): string | undefined; /** * Check whether the specified substitution is enabled for this block. * @param {string} name - The String substitution name. * @returns {boolean} */ hasSub(name: string): boolean; /** * Remove a substitution from this block. * @param {string} name - The String substitution name to remove. */ removeSub(name: string): void; /** * Alias for {@link getXrefText}. * @param {string|null} [xrefstyle=null] - Optional String style: 'full', 'short', or 'basic'. * @returns {Promise} the xreftext, or null. * @see {getXrefText} */ xreftext(xrefstyle?: string | null): Promise; /** * Generate and assign a caption to this block if not already assigned. * If the block has a title and a caption prefix is available, builds a caption * from the prefix and a counter, then stores it. * @param {string|null} [value=null] - The String caption to assign, or null to derive from document attributes. * @param {string} [captionContext=this.context] - The String context used to look up caption attributes. */ assignCaption(value?: string | null, captionContext?: string): void; /** * Selector criteria accepted by {@link AbstractBlock#findBy}. * @typedef {Object} FindBySelector * @property {string} [context] - node context (e.g. `'section'`, `'listing'`, `'paragraph'`, `'image'`) * @property {string} [style] - block style (e.g. `'source'`, `'NOTE'`) * @property {string} [role] - a CSS role that must appear in the node's role list * @property {string} [id] - exact node id; stops traversal after the first match * @property {boolean} [traverseDocuments] - when `true`, recurse into AsciiDoc table cells */ /** * Filter callback passed to {@link AbstractBlock#findBy}. * @callback FindByFilter * @param {AbstractBlock} node - the candidate block-level node being visited * @returns {boolean|string} a truthy value to include the node; `'prune'`, `'reject'` or `'stop'` to control traversal */ /** * Walk the document tree and find all block-level nodes that match * the selector and optional filter function. * * The selector is a plain object whose keys narrow the search: * - `context` {string} — node context (e.g. `'section'`, `'listing'`, `'paragraph'`, `'image'`) * - `style` {string} — block style (e.g. `'source'`, `'NOTE'`) * - `role` {string} — a CSS role that must appear in the node's role list * - `id` {string} — exact node id; stops traversal after the first match * - `traverseDocuments` {boolean} — when `true`, recurse into AsciiDoc table cells * * The optional filter function receives each candidate node and must return: * - a truthy value (or `true`) → include the node * - `'prune'` → include the node but do **not** recurse into its children * - `'reject'` → skip the node and its children * - `'stop'` → include the node (if it matched) and stop the entire traversal * * @param {FindBySelector|FindByFilter} [selector={}] - Selector criteria object, or a filter callback when called as `findBy(callback)`. * @param {FindByFilter|null} [filter=null] - Per-node filter callback; receives each candidate {@link AbstractBlock}. * @returns {AbstractBlock[]} array of matching block-level nodes. * * @example All source listing blocks * const listings = doc.findBy({ context: 'listing', style: 'source' }) * * @example All sections up to level 2 * const sections = doc.findBy({ context: 'section' }, (node) => node.level <= 2 || 'prune') * * @example Find a block by id * const [block] = doc.findBy({ id: 'my-anchor' }) * * @example All image blocks including those inside AsciiDoc table cells * const images = doc.findBy({ context: 'image', traverseDocuments: true }) * * @example Filter-only shorthand (no selector) * const verbatim = doc.findBy((b) => b.contentModel === ContentModel.VERBATIM) */ findBy(selector?: { /** * - node context (e.g. `'section'`, `'listing'`, `'paragraph'`, `'image'`) */ context?: string; /** * - block style (e.g. `'source'`, `'NOTE'`) */ style?: string; /** * - a CSS role that must appear in the node's role list */ role?: string; /** * - exact node id; stops traversal after the first match */ id?: string; /** * - when `true`, recurse into AsciiDoc table cells */ traverseDocuments?: boolean; } | ((node: AbstractBlock) => boolean | string), filter?: ((node: AbstractBlock) => boolean | string) | null): AbstractBlock[]; /** * Alias for {@link findBy}. * @param {FindBySelector|FindByFilter} [selector={}] - Selector criteria object, or a filter callback when called as `query(callback)`. * @param {FindByFilter|null} [filter=null] - Per-node filter callback; receives each candidate {@link AbstractBlock}. * @returns {AbstractBlock[]} array of matching block-level nodes. */ query(selector?: { /** * - node context (e.g. `'section'`, `'listing'`, `'paragraph'`, `'image'`) */ context?: string; /** * - block style (e.g. `'source'`, `'NOTE'`) */ style?: string; /** * - a CSS role that must appear in the node's role list */ role?: string; /** * - exact node id; stops traversal after the first match */ id?: string; /** * - when `true`, recurse into AsciiDoc table cells */ traverseDocuments?: boolean; } | ((node: AbstractBlock) => boolean | string), filter?: ((node: AbstractBlock) => boolean | string) | null): AbstractBlock[]; /** * Move to the next adjacent block in document order. * If the current block is the last item in a list, returns the following * sibling of the list block. * @returns {AbstractBlock|null} the next AbstractBlock, or null. */ nextAdjacentBlock(): AbstractBlock | null; /** * Get the content model of this block. * @returns {string} */ getContentModel(): string; /** * Set the content model of this block. * @param {string} val */ setContentModel(val: string): void; /** * Get the child blocks of this block. * @returns {AbstractBlock[]} */ getBlocks(): AbstractBlock[]; /** * Get the child Section blocks of this block. * @returns {AbstractBlock[]} */ getSections(): AbstractBlock[]; /** * Get the title of this block with substitutions applied. * @returns {string|null} */ getTitle(): string | null; /** * Set the raw title of this block. * @param {string|null} val */ setTitle(val: string | null): void; /** * Get the caption of this block. * @returns {string|undefined} */ getCaption(): string | undefined; /** * Set the caption of this block. * @param {string|null} val */ setCaption(val: string | null): void; /** * Get the captioned title of this block. * @returns {string} */ getCaptionedTitle(): string; /** * Get the style of this block. * @returns {string|null} */ getStyle(): string | null; /** * Set the style of this block. * @param {string|null} val */ setStyle(val: string | null): void; /** * Get the level of this block. * @returns {number|null} */ getLevel(): number | null; /** * Set the level of this block. * @param {number|null} val */ setLevel(val: number | null): void; /** * Get the source file where this block started. * @returns {string|undefined} the file path, or undefined when sourcemap is disabled. */ getFile(): string | undefined; /** * Get the source line number where this block started. * @returns {number|undefined} line number, or undefined when sourcemap is disabled. */ getLineNumber(): number | undefined; /** * Generate cross-reference text (xreftext) used to refer to this block. * Uses the explicit reftext if set. For sections or captioned blocks (blocks * with both a title and a caption), formats the text according to xrefstyle. * Falls back to the title, or null if no title is available. * @param {string|null} [xrefstyle=null] - Optional String style: 'full', 'short', or 'basic'. * @returns {Promise} the xreftext, or null. */ getXrefText(xrefstyle?: string | null): Promise; /** * Get the source location of this block. * @returns {Cursor|undefined} the Cursor source location object, or undefined when sourcemap is disabled. */ getSourceLocation(): Cursor | undefined; /** * Get the list of substitutions enabled for this block. * @returns {string[]} */ getSubstitutions(): string[]; /** * Check whether the specified substitution is enabled for this block. * @param {string} name * @returns {boolean} */ hasSubstitution(name: string): boolean; /** * Add the specified substitution to this block's substitutions list. * @param {string} name */ addSubstitution(name: string): void; /** * Remove the specified substitution from this block's substitutions list. * @param {string} name */ removeSubstitution(name: string): void; #private; } import { AbstractNode } from './abstract_node.js'; import type { Cursor } from './reader.js';