Class: MarkdownIt::RulesInline::StateInline

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src, md, env, outTokens) ⇒ StateInline




11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 11

def initialize(src, md, env, outTokens)
  @src          = src
  @env          = env
  @md           = md
  @tokens       = outTokens

  @pos          = 0
  @posMax       = @src.length
  @level        = 0
  @pending      = ''
  @pendingLevel = 0

  @cache        = {}      # Stores { start: end } pairs. Useful for backtrack
                          # optimization of pairs parse (emphasis, strikes).
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



8
9
10
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 8

def cache
  @cache
end

#envObject

Returns the value of attribute env.



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

def env
  @env
end

#levelObject

Returns the value of attribute level.



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

def level
  @level
end

#mdObject

Returns the value of attribute md.



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

def md
  @md
end

#pendingObject

Returns the value of attribute pending.



8
9
10
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 8

def pending
  @pending
end

#pendingLevelObject

Returns the value of attribute pendingLevel.



8
9
10
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 8

def pendingLevel
  @pendingLevel
end

#posObject

Returns the value of attribute pos.



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

def pos
  @pos
end

#posMaxObject

Returns the value of attribute posMax.



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

def posMax
  @posMax
end

#srcObject

Returns the value of attribute src.



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

def src
  @src
end

#tokensObject

Returns the value of attribute tokens.



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

def tokens
  @tokens
end

Instance Method Details

#push(type, tag, nesting) ⇒ Object

Push new token to “stream”. If pending text exists - flush it as text token




42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 42

def push(type, tag, nesting)
  pushPending unless @pending.empty?

  token       = Token.new(type, tag, nesting);
  @level     -= 1 if nesting < 0
  token.level = @level
  @level     += 1 if nesting > 0

  @pendingLevel = @level
  @tokens.push(token)
  return token
end

#pushPendingObject

Flush pending text




30
31
32
33
34
35
36
37
# File 'lib/motion-markdown-it/rules_inline/state_inline.rb', line 30

def pushPending
  token         = Token.new('text', '', 0)
  token.content = @pending
  token.level   = @pendingLevel
  @tokens.push(token)
  @pending      = ''
  return token
end