Function getClosestToken

  • Searches a full line for a token that matches a selector and contains position within the specified margins. Tokens are searched in reverse document order which means children are searched before their parents.

    Parameters

    • editor: PrismEditor

      Editor you want to search in.

    • selector: string

      CSS selector for the tokens you want to search for.

    • marginLeft: number = 0

      How far to the left of the token the position can be. Defaults to 0.

    • marginRight: number = marginLeft

      How far to the right of the token the position can be. Defaults to marginLeft.

    • position: number = ...

      Position to search in. Defaults to selectionStart.

    Returns undefined | HTMLSpanElement

    A span element if one's found or undefined if not.

    Example

    This will return a string token if the cursor is at least 1 character inside a string token

    getClosestToken(editor, '.string', -1)
    

Generated using TypeDoc