@asciidoctor/core
    Preparing search index...

    Class List

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _computingTitle: boolean
    attributes: any
    blocks: AbstractBlock<string>[]

    Array of AbstractBlock child blocks for this block. Only applies if content model is compound.

    contentModel: string

    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
    context: string
    defaultSubs: string[]
    document: Document
    id: string
    level: number
    nodeName: string
    numeral: string | number
    passthroughs: any[]
    sourceLocation: Cursor
    style: string
    subs: string[]

    Accessors

    • get caption(): string

      Get the caption for this block. For admonition blocks, returns the 'textlabel' attribute instead.

      Returns string

    • set caption(val: string): void

      Set the caption for this block.

      Parameters

      • val: string

      Returns void

    • get file(): string

      Get the source file where this block started.

      Returns string

    • get lineno(): number

      Get the source line number where this block started.

      Returns number

    • get logger(): any

      Provide a default logger. The Logging mixin (logging.js) overrides this getter on the prototype.

      Returns any

    • get number(): string | number

      Returns string | number

      Get/set the numeral of this section as an integer when possible.

    • set number(val: string | number): void

      Parameters

      • val: string | number

      Returns void

    • get reftext(): string

      Get the value of the reftext attribute with substitutions applied. The result is pre-computed during Document.parse() via precomputeReftext. Falls back to the raw reftext attribute if precomputeReftext() has not been called yet.

      Returns string

      the String reftext or null if not set.

    • get role(): string | string[]

      Alias for getRole.

      Returns string | string[]

    • set role(names: string | string[]): void

      Set the value of the role attribute on this node.

      Accepts a single role name, a space-separated String, or an Array.

      Parameters

      • names: string | string[]

        A single role name, a space-separated String, or an Array.

      Returns void

    • get title(): string

      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

      the converted String title, or null if the source title is falsy.

    • set title(val: string): void

      Set the String block title (clears the memoised converted title).

      Parameters

      • val: string

      Returns void

    Methods

    • Add the given role directly to this node.

      Parameters

      • name: string

        The String role name to add.

      Returns boolean

      true if the role was added, false if it was already present.

    • Get the converted alt text for this block image.

      Returns string

      string with XML special character and replacement substitutions applied.

    • 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.

      Parameters

      • Optionalvalue: string

        The String caption to assign, or null to derive from document attributes.

      • OptionalcaptionContext: string

        The String context used to look up caption attributes.

      Returns void

    • 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

      Parameters

      • Optionalselector: any

        Selector criteria object, or a filter callback when called as findBy(callback).

      • Optionalfilter: Function

        Per-node filter callback.

      Returns AbstractBlock<string>[]

      array of matching block-level nodes.

      const listings = doc.findBy({ context: 'listing', style: 'source' })
      
      const sections = doc.findBy({ context: 'section' }, (node) => node.level <= 2 || 'prune')
      
      const [block] = doc.findBy({ id: 'my-anchor' })
      
      const images = doc.findBy({ context: 'image', traverseDocuments: true })
      
      const verbatim = doc.findBy((b) => b.contentModel === ContentModel.VERBATIM)
      
    • Generate a data URI that embeds the image at the given local path.

      The image path is cleaned to prevent access outside the jail when the document safe level is SafeMode.SAFE or higher. The image data is read and Base64-encoded. In non-Node environments this method returns an empty data URI with a warning.

      Parameters

      • targetImage: string

        A String path to the target image.

      • OptionalassetDirKey: string

        The String attribute key for the image directory.

      Returns Promise<string>

      a Promise resolving to a String data URI.

    • Read the image data from the specified URI and generate a data URI.

      The image data is fetched and Base64-encoded. The MIME type is taken from the Content-Type response header.

      NOTE: This method is async in JS (the Fetch API is async). When called from imageUri, the caller must await the returned Promise.

      Parameters

      • imageUri: string

        The URI from which to read the image data (http/https/ftp).

      • OptionalcacheUri: boolean

        A Boolean to control caching (not yet supported in JS).

      Returns Promise<string>

      a Promise resolving to a String data URI.

    • Get the value of the specified attribute.

      Looks for the attribute on this node first. If not found and fallbackName is set, and this node is not the Document node, look for that attribute on the Document node. Otherwise, return defaultValue.

      Parameters

      • name: string

        The attribute name to resolve.

      • OptionaldefaultValue: any

        The value to return if the attribute is not found.

      • OptionalfallbackName: string | boolean

        When truthy, also checks the Document's attributes. Pass true to fall back using the same name, or a string to use a different name.

      Returns any

      the attribute value or defaultValue.

      block.getAttribute('language')           // → 'ruby' or null
      
      block.getAttribute('linenums', false)    // → false if not set
      
      block.getAttribute('source-highlighter', null, true)    // → falls back to doc attribute of same name
      block.getAttribute('linenums', null, 'source-linenums') // → falls back to 'source-linenums' on doc
    • Get the icon URI for the named icon.

      Parameters

      • name: string

        The String icon name.

      Returns Promise<string>

      a Promise resolving to a String URI.

    • Get the image URI for the target image.

      Parameters

      • targetImage: string

        The String target image path or URL.

      • OptionalassetDirKey: string

        The String asset directory attribute key.

      Returns Promise<string>

      a Promise resolving to a String URI.

    • Get the media URI for the target.

      Parameters

      • target: string

        The String target path or URL.

      • OptionalassetDirKey: string

        The String asset directory attribute key.

      Returns string

      a String URI.

    • Retrieve the String role names for this node as an Array.

      Returns string[]

      the role names as a String Array, empty if the role attribute is absent.

    • 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.

      Parameters

      • Optionalxrefstyle: string

        Optional String style: 'full', 'short', or 'basic'.

      Returns Promise<string>

      the xreftext, or null.

    • Check if the specified attribute is defined on this node, with optional value match and document-level fallback.

      Parameters

      • name: string

        The attribute name.

      • OptionalexpectedValue: any

        When truthy, also checks that the resolved value equals this.

      • OptionalfallbackName: string | boolean

        When truthy, also checks the Document's attributes. Pass true to use the same name, or a string for a different fallback name.

      Returns boolean

      block.hasAttribute('linenums')                       // → true/false
      
      block.hasAttribute('language', 'ruby')               // → true only when language === 'ruby'
      
      block.hasAttribute('source-highlighter', null, true) // → also checks doc-level attribute
      
    • Check whether this list has items (blocks).

      Returns boolean

    • Check if the specified option attribute is enabled on this node. This method checks whether the <name>-option attribute is set.

      Parameters

      • name: string

        The String or Symbol name of the option.

      Returns boolean

      true if the option is enabled, false otherwise.

    • Check if the specified role name is present in this node's role list.

      Parameters

      • name: string

        The String role name to find.

      Returns boolean

    • Check if the role attribute is set on this node, optionally matching an exact value.

      Unlike hasRole, which checks for an individual role name within a space-separated list, this method tests the raw role attribute string as a whole.

      Parameters

      • OptionalexpectedValue: string

        When provided, checks that the role attribute equals this string exactly.

      Returns boolean

      node.hasRoleAttribute()         // → true if role attribute is set at all
      node.hasRoleAttribute('lead') // → true only when role === 'lead' (not 'lead primary')
    • Check whether the specified substitution is enabled for this block.

      Parameters

      • name: string

        The String substitution name.

      Returns boolean

    • Construct a reference or data URI to an icon image for the given name.

      If the 'icon' attribute is set on this node the name is ignored and the attribute value is used as the target path. Otherwise the icon path is built from 'iconsdir', the name, and 'icontype' (default: 'png').

      Parameters

      • name: string

        The String name of the icon.

      Returns Promise<string>

      a Promise resolving to a String reference or data URI for the icon image.

    • Construct a URI reference or data URI to the target image.

      If the target image is already a URI it is left untouched (unless data-uri conversion is requested). The image is resolved relative to the directory named by assetDirKey. When data-uri is enabled and the safe level permits, the image is embedded as a Base64 data URI.

      NOTE: When the document has both 'data-uri' and 'allow-uri-read' enabled and the resolved image URL is a remote URI, this method returns a Promise rather than a String. Await the result when that combination may be active.

      Parameters

      • targetImage: string

        A String path to the target image.

      • OptionalassetDirKey: string

        The String attribute key for the image directory.

      Returns Promise<string>

      a Promise resolving to a String reference or data URI.

    • Check whether this node has reftext — either an explicit 'reftext' attribute or a title that can serve as the cross-reference text. Mirrors Ruby's AbstractNode#reftext?

      Returns boolean

    • Get the list marker keyword for the specified list type.

      Parameters

      • OptionallistType: string

        The String list type (default: this.style).

      Returns string

      the single-character String keyword for the list marker.

    • Construct a URI reference to the target media.

      Parameters

      • target: string

        A String reference to the target media.

      • OptionalassetDirKey: string

        The String attribute key for the media directory.

      Returns string

      a String reference for the target media.

    • Normalize the asset file or directory to a concrete and rinsed path.

      Delegates to normalizeSystemPath with start set to document.baseDir.

      Parameters

      • assetRef: string

        The String asset reference to normalize.

      • OptionalassetName: string

        The String label for the asset used in messages.

      • Optionalautocorrect: boolean

        A Boolean indicating whether to recover from an illegal path.

      Returns string

      the normalized String path.

    • Resolve and normalize a secure path from the target and start paths.

      Prevents resolving a path outside the jail (defaulting to document.baseDir) when the document safe level is SafeMode.SAFE or higher.

      Parameters

      • target: string

        The String target path.

      • Optionalstart: string

        The String start (parent) path.

      • Optionaljail: string

        The String jail path.

      • Optionalopts: any

        A plain object of options:

        • recover {boolean} - Whether to automatically recover for illegal paths.
        • targetName {string} - Label used in messages for the path being resolved.

      Returns string

      the resolved String path.

      if a jail is specified and the resolved path is outside it.

    • Normalize the web path using the PathResolver.

      Parameters

      • target: string

        The String target path.

      • Optionalstart: string

        The String start (parent) path.

      • OptionalpreserveUriTarget: boolean

        Whether a URI target should be preserved as-is.

      Returns string

      the resolved String path.

    • Check whether this list is an outline list (unordered or ordered).

      Returns boolean

    • Pre-compute the reftext with substitutions applied asynchronously. Called during Document.parse() so the synchronous getter works during conversion.

      Returns Promise<void>

    • 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 () can return null (→ "[refid]" fallback).

      Returns Promise<void>

    • Read the contents of the file at the specified path.

      This method checks that the file is readable before attempting to read it.

      Parameters

      • path: string

        The String path from which to read the contents.

      • Optionalopts: any

        A plain object of options:

        • warnOnFailure {boolean} - Whether a warning is issued when the file cannot be read (default: false).
        • normalize {boolean} - Whether lines are normalized and coerced to UTF-8 (default: false).
        • label {string} - Label for the file used in warning messages.

      Returns Promise<string>

      a Promise resolving to the file content, or null if not readable.

    • Resolve the URI or system path to the target, then read and return its contents.

      When the resolved path is a URI and allow-uri-read is enabled, the content is fetched via the Fetch API (async). When it is a local path, the file is read via readAsset.

      Parameters

      • target: string

        The URI or local path String from which to read the data.

      • Optionalopts: any

        A plain object of options:

        • label {string} - Label used in warning messages (default: 'asset').
        • normalize {boolean} - Whether the data should be normalized (default: false).
        • start {string} - Relative base path for resolving the target.
        • warnOnFailure {boolean} - Whether warnings are issued on failure (default: true).
        • warnIfEmpty {boolean} - Whether a warning is issued when the target contents are empty (default: false).

      Returns Promise<string>

      a Promise resolving to the content, or null on failure.

    • Remove the attribute from this node.

      Parameters

      • name: string

        The attribute name to remove.

      Returns any

      the previous value, or undefined if the attribute was not present.

    • Remove the given role directly from this node.

      Parameters

      • name: string

        The String role name to remove.

      Returns boolean

      true if the role was removed, false if it was not present.

    • Set the value of the specified attribute on this node.

      Parameters

      • name: string

        The attribute name to assign.

      • Optionalvalue: any

        The value to assign.

      • Optionaloverwrite: boolean

        When false, does nothing if the attribute already exists.

      Returns string | boolean

      true if the attribute was set, false if blocked by overwrite=false. Subclasses (e.g. Document) may return the resolved value string or null when the attribute is locked.

    • Update the context of this block, also updating the node name.

      Parameters

      • context: string

        The String context to assign to this block.

      Returns void

    • Set the specified option on this node by setting the <name>-option attribute.

      Parameters

      • name: string

        The String name of the option.

      Returns void

    • Set the value of the role attribute on this node.

      Accepts a single role name, a space-separated String, an Array, or spread arguments.

      Parameters

      • ...names: (string | string[])[]

        A single role name, a space-separated String, an Array, or multiple role names as spread arguments.

      Returns string

      the value of the role attribute.

    • Update the attributes of this node with the new values.

      Parameters

      • newAttributes: any

        A plain object of additional attributes to assign.

      Returns any

      the updated attributes object on this node.

    • Alias for getXrefText.

      Parameters

      • Optionalxrefstyle: string

        Optional String style: 'full', 'short', or 'basic'.

      Returns Promise<string>

      the xreftext, or null.