Foundry Virtual Tabletop - API Documentation - Version 14
    Preparing search index...

    A collection of helper functions and utility methods related to the rich text editor.

    Index

    Accessors

    Methods

    • Internal

      Upload an image to a document's asset path.

      Parameters

      • uuid: string

        The document's UUID.

      • file: File

        The image file to upload.

      Returns Promise<string | void>

      The path to the uploaded image.

    • Activate interaction listeners for the interior content of the editor frame.

      Parameters

      • document: Document

        The document to bind listeners to.

      Returns void

    • Create a Rich Text Editor. The current implementation uses ProseMirror.

      Parameters

      • options: { engine?: string } = {}

        Configuration options provided to the Editor init

        • Optionalengine?: string

          Which rich text editor engine to use.

      • content: string = ""

        Initial HTML or text content to populate the editor with

      Returns ProseMirrorEditor

      The editor instance.

    • Helper method to create an anchor element.

      Parameters

      Returns HTMLAnchorElement

    • Safely decode an HTML string, removing invalid tags and converting entities back to unicode characters.

      Parameters

      • html: string

        The original encoded HTML string

      Returns string

      The decoded unicode string

    • Enrich HTML content by replacing or augmenting components of it

      Parameters

      • content: string

        The original HTML content (as a string)

      • Optionaloptions: EnrichmentOptions = {}

        Additional options which configure how HTML is enriched

      Returns Promise<string>

      The enriched HTML content

    • Given a Drop event, returns a Content link if possible such as "@Actor[ABC123]", else null

      Parameters

      • eventData: object

        The parsed object of data provided by the transfer event

      • Optionaloptions: { label?: string; relativeTo?: any } = {}

        Additional options to configure link creation.

        • Optionallabel?: string

          A custom label to use instead of the document's name.

        • OptionalrelativeTo?: any

          A document to generate the link relative to.

      Returns Promise<string | null>

    • Extract JSON data from a drag/drop event.

      Parameters

      • event: DragEvent

        The drag event which contains JSON data.

      Returns object

      The extracted JSON data. The object will be empty if the DragEvent did not contain JSON-parseable data.

    • Preview an HTML fragment by constructing a substring of a given length from its inner text.

      Parameters

      • content: string

        The raw HTML to preview

      • length: number = 250

        The desired length

      Returns string

      The previewed HTML

    • Sanitises an HTML fragment and removes any non-paragraph-style text.

      Parameters

      • html: HTMLElement

        The root HTML element.

      Returns HTMLElement

    • Truncate a fragment of text to a maximum number of characters.

      Parameters

      • text: string

        The original text fragment that should be truncated to a maximum length

      • Optionaloptions: { maxLength?: number; splitWords?: boolean; suffix?: string | null } = {}

        Options which affect the behavior of text truncation

        • OptionalmaxLength?: number

          The maximum allowed length of the truncated string.

        • OptionalsplitWords?: boolean

          Whether to truncate by splitting on white space (if true) or breaking words.

        • Optionalsuffix?: string | null

          A suffix string to append to denote that the text was truncated.

      Returns string

      The truncated text string

    • Protected

      Match any custom registered regex patterns and apply their replacements.

      Parameters

      • config: TextEditorEnricherConfig

        The custom enricher configuration.

      • text: Text[]

        The existing text content.

      • Optionaloptions: EnrichmentOptions

        Options provided to customize text enrichment

      Returns Promise<boolean>

      Whether any replacements were made, requiring the text nodes to be updated.

    • Protected

      Create a dynamic document link from a regular expression match

      Parameters

      • match: RegExpMatchArray

        The regular expression match

      • Optionaloptions: EnrichmentOptions = {}

        Additional options to configure enrichment behaviour

        • Optionalcustom?: boolean

          Apply custom enrichers?

        • Optionaldocuments?: boolean

          Replace dynamic document links?

        • Optionalembeds?: boolean

          Replace embedded content?

        • Replace hyperlink content?

        • OptionalrelativeTo?: any

          A document to resolve relative UUIDs against.

        • OptionalrollData?: object | Function

          The data object providing context for inline rolls, or a function that produces it.

        • Optionalrolls?: boolean

          Replace inline dice rolls?

        • Optionalsecrets?: boolean

          Include unrevealed secret tags in the final HTML? If false, unrevealed secret blocks will be removed.

      Returns Promise<HTMLAnchorElement>

      An HTML element for the document link.

    • Protected

      Replace a hyperlink-like string with an actual HTML <a> tag

      Parameters

      • match: RegExpMatchArray

        The regular expression match

      • Optionaloptions: EnrichmentOptions = {}

        Options provided to customize text enrichment

      Returns Promise<HTMLAnchorElement>

      An HTML element for the document link

    • Protected

      Replace an inline roll formula with a rollable <a> element or an eagerly evaluated roll result

      Parameters

      • match: RegExpMatchArray

        The regular expression match array

      • rollData: object

        Provided roll data for use in roll evaluation

      • Optionaloptions: EnrichmentOptions = {}

        Options provided to customize text enrichment.

      Returns Promise<HTMLAnchorElement | null>

      The replaced match. Returns null if the contained command is not a valid roll expression.

    • Protected

      Embed content from another Document.

      Parameters

      • match: RegExpMatchArray

        The regular expression match.

      • Optionaloptions: EnrichmentOptions = {}

        Options provided to customize text enrichment.

      Returns Promise<HTMLElement | null>

      A representation of the Document as HTML content, or null if the Document could not be embedded.

    • Protected

      Convert text of the form @UUID[uuid]{name} to anchor elements.

      Parameters

      • text: Text[]

        The existing text content

      • Optionaloptions: EnrichmentOptions = {}

        Options provided to customize text enrichment

        • Optionalcustom?: boolean

          Apply custom enrichers?

        • Optionaldocuments?: boolean

          Replace dynamic document links?

        • Optionalembeds?: boolean

          Replace embedded content?

        • Replace hyperlink content?

        • OptionalrelativeTo?: any

          A document to resolve relative UUIDs against.

        • OptionalrollData?: object | Function

          The data object providing context for inline rolls, or a function that produces it.

        • Optionalrolls?: boolean

          Replace inline dice rolls?

        • Optionalsecrets?: boolean

          Include unrevealed secret tags in the final HTML? If false, unrevealed secret blocks will be removed.

      Returns Promise<boolean>

      Whether any content links were replaced and the text nodes need to be updated.

    • Protected

      Handle embedding Document content with @Embed[uuid]{label} text.

      Parameters

      • text: Text[]

        The existing text content.

      • Optionaloptions: EnrichmentOptions = {}

        Options provided to customize text enrichment.

      Returns Promise<boolean>

      Whether any embeds were replaced and the text nodes need to be updated.

    • Protected

      Convert URLs into anchor elements.

      Parameters

      • text: Text[]

        The existing text content

      • Optionaloptions: EnrichmentOptions = {}

        Options provided to customize text enrichment

      Returns Promise<boolean>

      Whether any hyperlinks were replaced and the text nodes need to be updated

    • Protected

      Convert text of the form [[roll]] to anchor elements.

      Parameters

      • rollData: object | Function

        The data object providing context for inline rolls.

      • text: Text[]

        The existing text content.

      • Optionaloptions: EnrichmentOptions = {}

        Options provided to customize text enrichment.

      Returns Promise<boolean>

      Whether any inline rolls were replaced and the text nodes need to be updated.

    • Protected Internal

      A method that can be extended by subclasses to perform final post-enrichment operations on an HTML fragment. Final changes should be made in-place, mutating the provided HTML element. Note: This API is experimental and may be removed in later versions without deprecation.

      Parameters

      • html: HTMLDivElement

        A div element containing the enriched HTML

      • options: EnrichmentOptions

        Provided enrichment options

      Returns Promise<void>

      A promise which resolves once finalization has completed

    • Protected

      Handle left-mouse clicks on an inline roll, dispatching the formula or displaying the tooltip

      Parameters

      • event: MouseEvent

        The initiating click event

      Returns Promise<any>

    • Protected

      Parse the embed configuration to be passed to ClientDocument#toEmbed. The return value will be an object of any key=value pairs included with the configuration, as well as a separate values property that contains all the options supplied that were not in key=value format. If a uuid key is supplied it is used as the Document's UUID, otherwise the first supplied UUID is used.

      Parameters

      • raw: string

        The raw matched config string.

      • Optionaloptions: object = {}

        Options forwarded to parseUuid.

      Returns DocumentHTMLEmbedConfig

      TextEditor._parseEmbedConfig('uuid=Actor.xyz caption="Example Caption" cite=false');
      // Returns: { uuid: "Actor.xyz", caption: "Example Caption", cite: false, values: [] }

      TextEditor._parseEmbedConfig('Actor.xyz caption="Example Caption" inline');
      // Returns: { uuid: "Actor.xyz", caption: "Example Caption", values: ["inline"] }
    • Protected

      Scan for compendium UUIDs and retrieve Documents in batches so that they are in cache when enrichment proceeds.

      Parameters

      • text: Text[]

        The text nodes to scan.

      • Optionaloptions: EnrichmentOptions = {}

        Options provided to customize text enrichment

      Returns Promise<void>

    • Protected

      Facilitate the replacement of text node content using a matching regex rule and a provided replacement function.

      Parameters

      • text: Text[]

        The text nodes to match and replace.

      • rgx: RegExp

        The provided regular expression for matching and replacement

      • func: TextContentReplacer

        The replacement function

      • Optionaloptions: TextReplacementOptions = {}

        Options to configure text replacement behavior.

      Returns boolean

      Whether a replacement was made.