Class: MarkdownIt::Token
- Inherits:
-
Object
- Object
- MarkdownIt::Token
- Defined in:
- lib/motion-markdown-it/token.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Returns the value of attribute attrs.
-
#block ⇒ Object
Returns the value of attribute block.
-
#children ⇒ Object
Returns the value of attribute children.
-
#content ⇒ Object
Returns the value of attribute content.
-
#hidden ⇒ Object
Returns the value of attribute hidden.
-
#info ⇒ Object
Returns the value of attribute info.
-
#level ⇒ Object
Returns the value of attribute level.
-
#map ⇒ Object
Returns the value of attribute map.
-
#markup ⇒ Object
Returns the value of attribute markup.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#nesting ⇒ Object
Returns the value of attribute nesting.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#attrGet(name) ⇒ Object
Token.attrGet(name).
-
#attrIndex(name) ⇒ Object
-
Token.attrIndex(name) -> Number * * Search attribute index by name.
-
-
#attrJoin(name, value) ⇒ Object
Token.attrJoin(name, value).
-
#attrPush(attrData) ⇒ Object
-
Token.attrPush(attrData) * * Add ‘[ name, value ]` attribute to list.
-
-
#attrSet(name, value) ⇒ Object
Token.attrSet(name, value).
-
#initialize(type, tag, nesting) ⇒ Token
constructor
new Token(type, tag, nesting).
-
#to_json ⇒ Object
——————————————————————————.
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
#attrs ⇒ Object
Returns the value of attribute attrs.
6 7 8 |
# File 'lib/motion-markdown-it/token.rb', line 6 def attrs @attrs end |
#block ⇒ Object
Returns the value of attribute block.
7 8 9 |
# File 'lib/motion-markdown-it/token.rb', line 7 def block @block end |
#children ⇒ Object
Returns the value of attribute children.
6 7 8 |
# File 'lib/motion-markdown-it/token.rb', line 6 def children @children end |
#content ⇒ Object
Returns the value of attribute content.
7 8 9 |
# File 'lib/motion-markdown-it/token.rb', line 7 def content @content end |
#hidden ⇒ Object
Returns the value of attribute hidden.
7 8 9 |
# File 'lib/motion-markdown-it/token.rb', line 7 def hidden @hidden end |
#info ⇒ Object
Returns the value of attribute info.
7 8 9 |
# File 'lib/motion-markdown-it/token.rb', line 7 def info @info end |
#level ⇒ Object
Returns the value of attribute level.
6 7 8 |
# File 'lib/motion-markdown-it/token.rb', line 6 def level @level end |
#map ⇒ Object
Returns the value of attribute map.
6 7 8 |
# File 'lib/motion-markdown-it/token.rb', line 6 def map @map end |
#markup ⇒ Object
Returns the value of attribute markup.
7 8 9 |
# File 'lib/motion-markdown-it/token.rb', line 7 def markup @markup end |
#meta ⇒ Object
Returns the value of attribute meta.
7 8 9 |
# File 'lib/motion-markdown-it/token.rb', line 7 def @meta end |
#nesting ⇒ Object
Returns the value of attribute nesting.
6 7 8 |
# File 'lib/motion-markdown-it/token.rb', line 6 def nesting @nesting end |
#tag ⇒ Object
Returns the value of attribute tag.
6 7 8 |
# File 'lib/motion-markdown-it/token.rb', line 6 def tag @tag end |
#type ⇒ Object
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
#attrGet(name) ⇒ Object
Token.attrGet(name)
Get the value of attribute ‘name`, or null if it does not exist.
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/motion-markdown-it/token.rb', line 134 def attrGet(name) idx = attrIndex(name) value = nil if idx >= 0 value = @attrs[idx][1] end return value end |
#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 |
#attrJoin(name, value) ⇒ Object
Token.attrJoin(name, value)
Join value to existing attribute via space. Or create new attribute if not exists. Useful to operate with token classes.
150 151 152 153 154 155 156 157 158 |
# File 'lib/motion-markdown-it/token.rb', line 150 def attrJoin(name, value) idx = attrIndex(name) if idx < 0 attrPush([ name, value ]) else @attrs[idx][1] = @attrs[idx][1] + ' ' + value end 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 |
#attrSet(name, value) ⇒ Object
Token.attrSet(name, value)
Set ‘name` attribute to `value`. Override old value if exists.
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/motion-markdown-it/token.rb', line 119 def attrSet(name, value) idx = attrIndex(name) attrData = [ name, value ] if idx < 0 attrPush(attrData) else @attrs[idx] = attrData end end |
#to_json ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/motion-markdown-it/token.rb', line 161 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 |