Class: Mdlint::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/mdlint/token.rb,
sig/mdlint.rbs

Constant Summary collapse

BLOCK_TYPES =
%i[
  document
  heading_open heading_close
  paragraph_open paragraph_close
  bullet_list_open bullet_list_close
  ordered_list_open ordered_list_close
  list_item_open list_item_close
  blockquote_open blockquote_close
  code_block fence
  hr html_block front_matter table directive math_block footnote_definition
  inline
].freeze
INLINE_TYPES =
%i[
  text
  strong_open strong_close
  em_open em_close
  s_open s_close
  math_inline footnote_ref
  code_inline
  link_open link_close
  image
  softbreak hardbreak
  html_inline
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, **kwargs) ⇒ Token

Returns a new instance of Token.

Parameters:

  • type: (Symbol)
  • (Object)


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mdlint/token.rb', line 7

def initialize(type:, **kwargs)
  @type = type
  @tag = kwargs[:tag]
  @nesting = kwargs[:nesting] || 0
  @level = kwargs[:level] || 0
  @content = kwargs[:content] || ""
  @markup = kwargs[:markup] || ""
  @info = kwargs[:info] || ""
  @meta = kwargs[:meta] || {}
  @map = kwargs[:map]
  @children = kwargs[:children] || []
  @attrs = kwargs[:attrs] || {}
end

Instance Attribute Details

#attrsHash[Symbol, untyped]

Returns the value of attribute attrs.

Returns:

  • (Hash[Symbol, untyped])


5
6
7
# File 'lib/mdlint/token.rb', line 5

def attrs
  @attrs
end

#childrenArray[Token]

Returns the value of attribute children.

Returns:



5
6
7
# File 'lib/mdlint/token.rb', line 5

def children
  @children
end

#contentString

Returns the value of attribute content.

Returns:

  • (String)


5
6
7
# File 'lib/mdlint/token.rb', line 5

def content
  @content
end

#infoString

Returns the value of attribute info.

Returns:

  • (String)


5
6
7
# File 'lib/mdlint/token.rb', line 5

def info
  @info
end

#levelInteger

Returns the value of attribute level.

Returns:

  • (Integer)


5
6
7
# File 'lib/mdlint/token.rb', line 5

def level
  @level
end

#mapArray[Integer]?

Returns the value of attribute map.

Returns:

  • (Array[Integer], nil)


5
6
7
# File 'lib/mdlint/token.rb', line 5

def map
  @map
end

#markupString

Returns the value of attribute markup.

Returns:

  • (String)


5
6
7
# File 'lib/mdlint/token.rb', line 5

def markup
  @markup
end

#metaHash[Symbol, untyped]

Returns the value of attribute meta.

Returns:

  • (Hash[Symbol, untyped])


5
6
7
# File 'lib/mdlint/token.rb', line 5

def meta
  @meta
end

#nestingInteger

Returns the value of attribute nesting.

Returns:

  • (Integer)


5
6
7
# File 'lib/mdlint/token.rb', line 5

def nesting
  @nesting
end

#tagString?

Returns the value of attribute tag.

Returns:

  • (String, nil)


5
6
7
# File 'lib/mdlint/token.rb', line 5

def tag
  @tag
end

#typeSymbol

Returns the value of attribute type.

Returns:

  • (Symbol)


5
6
7
# File 'lib/mdlint/token.rb', line 5

def type
  @type
end

Instance Method Details

#block?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/mdlint/token.rb', line 33

def block?
  BLOCK_TYPES.include?(@type)
end

#closing?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/mdlint/token.rb', line 25

def closing?
  @nesting == -1
end

#inline?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/mdlint/token.rb', line 37

def inline?
  INLINE_TYPES.include?(@type)
end

#opening?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/mdlint/token.rb', line 21

def opening?
  @nesting == 1
end

#self_closing?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/mdlint/token.rb', line 29

def self_closing?
  @nesting.zero?
end