Class: MarkdownIt::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-markdown-it/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, tag, nesting) ⇒ Token

new Token(type, tag, nesting)

Create new token and fill passed properties.




13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/motion-markdown-it/token.rb', line 13

def initialize(type, tag, nesting)
  #  * Token#type -> String
  #  *
  #  * Type of the token (string, e.g. "paragraph_open")
  @type     = type

   # * Token#tag -> String
   # *
   # * html tag name, e.g. "p"
  @tag      = tag

   # * Token#attrs -> Array
   # *
   # * Html attributes. Format: `[ [ name1, value1 ], [ name2, value2 ] ]`
  @attrs    = nil

   # * Token#map -> Array
   # *
   # * Source map info. Format: `[ line_begin, line_end ]`
  @map      = nil

   # * Token#nesting -> Number
   # *
   # * Level change (number in {-1, 0, 1} set), where:
   # *
   # * -  `1` means the tag is opening
   # * -  `0` means the tag is self-closing
   # * - `-1` means the tag is closing
  @nesting  = nesting

   # * Token#level -> Number
   # *
   # * nesting level, the same as `state.level`
  @level    = 0

   # * Token#children -> Array
   # *
   # * An array of child nodes (inline and img tokens)
  @children = nil

   # * Token#content -> String
   # *
   # * In a case of self-closing tag (code, html, fence, etc.),
   # * it has contents of this tag.
  @content  = ''

   # * Token#markup -> String
   # *
   # * '*' or '_' for emphasis, fence string for fence, etc.
  @markup   = ''

   # * Token#info -> String
   # *
   # * fence infostring
  @info     = ''

   # * Token#meta -> Object
   # *
   # * A place for plugins to store an arbitrary data
  @meta     = nil

   # * Token#block -> Boolean
   # *
   # * True for block-level tokens, false for inline tokens.
   # * Used in renderer to calculate line breaks
  @block    = false

   # * Token#hidden -> Boolean
   # *
   # * If it's true, ignore this element when rendering. Used for tight lists
   # * to hide paragraphs.
  @hidden   = false
end

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs.



6
7
8
# File 'lib/motion-markdown-it/token.rb', line 6

def attrs
  @attrs
end

#blockObject

Returns the value of attribute block.



7
8
9
# File 'lib/motion-markdown-it/token.rb', line 7

def block
  @block
end

#childrenObject

Returns the value of attribute children.



6
7
8
# File 'lib/motion-markdown-it/token.rb', line 6

def children
  @children
end

#contentObject

Returns the value of attribute content.



7
8
9
# File 'lib/motion-markdown-it/token.rb', line 7

def content
  @content
end

#hiddenObject

Returns the value of attribute hidden.



7
8
9
# File 'lib/motion-markdown-it/token.rb', line 7

def hidden
  @hidden
end

#infoObject

Returns the value of attribute info.



7
8
9
# File 'lib/motion-markdown-it/token.rb', line 7

def info
  @info
end

#levelObject

Returns the value of attribute level.



6
7
8
# File 'lib/motion-markdown-it/token.rb', line 6

def level
  @level
end

#mapObject

Returns the value of attribute map.



6
7
8
# File 'lib/motion-markdown-it/token.rb', line 6

def map
  @map
end

#markupObject

Returns the value of attribute markup.



7
8
9
# File 'lib/motion-markdown-it/token.rb', line 7

def markup
  @markup
end

#metaObject

Returns the value of attribute meta.



7
8
9
# File 'lib/motion-markdown-it/token.rb', line 7

def meta
  @meta
end

#nestingObject

Returns the value of attribute nesting.



6
7
8
# File 'lib/motion-markdown-it/token.rb', line 6

def nesting
  @nesting
end

#tagObject

Returns the value of attribute tag.



6
7
8
# File 'lib/motion-markdown-it/token.rb', line 6

def tag
  @tag
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/motion-markdown-it/token.rb', line 6

def type
  @type
end

Instance Method Details

#attrIndex(name) ⇒ Object

  • Token.attrIndex(name) -> Number

*

  • Search attribute index by name.




92
93
94
95
96
97
98
99
100
101
# File 'lib/motion-markdown-it/token.rb', line 92

def attrIndex(name)
  return -1 if !@attrs

  attrs = @attrs

  attrs.each_with_index do |attr_, index|
    return index if attr_[0] == name
  end
  return -1
end

#attrPush(attrData) ⇒ Object

  • Token.attrPush(attrData)

*

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




107
108
109
110
111
112
113
# File 'lib/motion-markdown-it/token.rb', line 107

def attrPush(attrData)
  if @attrs
    @attrs.push(attrData)
  else
    @attrs = [ attrData ]
  end
end

#to_jsonObject




116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/motion-markdown-it/token.rb', line 116

def to_json
  {
    type: @type,
    tag: @tag,
    attrs: @attrs,
    map: @map,
    nesting: @nesting,
    level: @level,
    children: @children.nil? ? nil : @children.each {|t| t.to_json},
    content: @content,
    markup: @markup,
    info: @info,
    meta: @meta,
    block: @block,
    hidden: @hidden
  }
end