Skip to content

Class: Token

Defined in: token.ts:14

Constructors

Constructor

ts
new Token(
   type, 
   tag, 
   nesting): Token;

Defined in: token.ts:89

Create new token and fill passed properties.

Parameters

type

string

tag

string

nesting

Nesting

Returns

Token

Properties

attrs

ts
attrs: HTMLAttribute[] | null = null;

Defined in: token.ts:28

HTML attributes. Format: [ [ name1, value1 ], [ name2, value2 ] ]


block

ts
block: boolean = false;

Defined in: token.ts:78

True for block-level tokens, false for inline tokens. Used in renderer to calculate line breaks


children

ts
children: Token[] | null = null;

Defined in: token.ts:48

An array of child nodes (inline and img tokens)


content

ts
content: string = '';

Defined in: token.ts:54

In a case of self-closing tag (code, html, fence, etc.), it has contents of this tag.


hidden

ts
hidden: boolean = false;

Defined in: token.ts:84

If it's true, ignore this element when rendering. Used for tight lists to hide paragraphs.


info

ts
info: string = '';

Defined in: token.ts:67

  • Info string for "fence" tokens
  • The value "auto" for autolink "link_open" and "link_close" tokens
  • The string value of the item marker for ordered-list "list_item_open" tokens
  • Label string of "reference" tokens

level

ts
level: number = 0;

Defined in: token.ts:43

Nesting level, the same as state.level


map

ts
map: SourceMapLineRange | null = null;

Defined in: token.ts:33

Source map info. Format: [ line_begin, line_end ]


markup

ts
markup: string = '';

Defined in: token.ts:59

'*' or '_' for emphasis, fence string for fence, etc.


meta

ts
meta: any = null;

Defined in: token.ts:72

A place for plugins to store an arbitrary data


nesting

ts
nesting: Nesting;

Defined in: token.ts:38

Level change (number in {-1, 0, 1} set)


tag

ts
tag: string;

Defined in: token.ts:23

HTML tag name, e.g. "p"


type

ts
type: string;

Defined in: token.ts:18

Type of the token, e.g. "paragraph_open"

Methods

attrGet()

ts
attrGet(name): string | null;

Defined in: token.ts:139

Get the value of attribute name, or null if it does not exist.

Parameters

name

string

Returns

string | null


attrIndex()

ts
attrIndex(name): number;

Defined in: token.ts:98

Search attribute index by name.

Parameters

name

string

Returns

number


attrJoin()

ts
attrJoin(name, value): void;

Defined in: token.ts:152

Join value to existing attribute via space. Or create new attribute if not exists. Useful to operate with token classes.

Parameters

name

string

value

string

Returns

void


attrPush()

ts
attrPush(attrData): void;

Defined in: token.ts:114

Add [ name, value ] attribute to list. Init attrs if necessary

Parameters

attrData

HTMLAttribute

Returns

void


attrSet()

ts
attrSet(name, value): void;

Defined in: token.ts:125

Set name attribute to value. Override old value if exists.

Parameters

name

string

value

string

Returns

void

Released under the MIT License.