Class: MarkdownIt::ParserInline
- Inherits:
-
Object
- Object
- MarkdownIt::ParserInline
- Defined in:
- lib/motion-markdown-it/parser_inline.rb
Constant Summary collapse
- RULES =
Parser rules
[ [ 'text', lambda { |state, startLine| RulesInline::Text.text(state, startLine) } ], [ 'newline', lambda { |state, startLine| RulesInline::Newline.newline(state, startLine) } ], [ 'escape', lambda { |state, startLine| RulesInline::Escape.escape(state, startLine) } ], [ 'backticks', lambda { |state, startLine| RulesInline::Backticks.backtick(state, startLine) } ], [ 'strikethrough', lambda { |state, startLine| RulesInline::Strikethrough.strikethrough(state, startLine) } ], [ 'emphasis', lambda { |state, startLine| RulesInline::Emphasis.emphasis(state, startLine) } ], [ 'link', lambda { |state, startLine| RulesInline::Link.link(state, startLine) } ], [ 'image', lambda { |state, startLine| RulesInline::Image.image(state, startLine) } ], [ 'autolink', lambda { |state, startLine| RulesInline::Autolink.autolink(state, startLine) } ], [ 'html_inline', lambda { |state, startLine| RulesInline::HtmlInline.html_inline(state, startLine) } ], [ 'entity', lambda { |state, startLine| RulesInline::Entity.entity(state, startLine) } ], ]
Instance Attribute Summary collapse
-
#ruler ⇒ Object
Returns the value of attribute ruler.
Instance Method Summary collapse
-
#initialize ⇒ ParserInline
constructor
——————————————————————————.
-
#parse(str, md, env, outTokens) ⇒ Object
ParserInline.parse(str, md, env, outTokens).
-
#skipToken(state) ⇒ Object
Skip single token by running all rules in validation mode; returns ‘true` if any rule reported success ——————————————————————————.
-
#tokenize(state) ⇒ Object
Generate tokens for input range ——————————————————————————.
Constructor Details
#initialize ⇒ ParserInline
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/motion-markdown-it/parser_inline.rb', line 30 def initialize # ParserInline#ruler -> Ruler # # [[Ruler]] instance. Keep configuration of inline rules. @ruler = Ruler.new RULES.each do |rule| @ruler.push(rule[0], rule[1]) end end |
Instance Attribute Details
#ruler ⇒ Object
Returns the value of attribute ruler.
9 10 11 |
# File 'lib/motion-markdown-it/parser_inline.rb', line 9 def ruler @ruler end |
Instance Method Details
#parse(str, md, env, outTokens) ⇒ Object
ParserInline.parse(str, md, env, outTokens)
Process input string and push inline tokens into ‘outTokens`
114 115 116 117 118 |
# File 'lib/motion-markdown-it/parser_inline.rb', line 114 def parse(str, md, env, outTokens) state = RulesInline::StateInline.new(str, md, env, outTokens) tokenize(state) end |
#skipToken(state) ⇒ Object
Skip single token by running all rules in validation mode; returns ‘true` if any rule reported success
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 |
# File 'lib/motion-markdown-it/parser_inline.rb', line 44 def skipToken(state) pos = state.pos rules = @ruler.getRules('') len = rules.length maxNesting = state.md.[:maxNesting] cache = state.cache if cache[pos] != nil state.pos = cache[pos] return end # istanbul ignore else if state.level < maxNesting 0.upto(len -1) do |i| if rules[i].call(state, true) cache[pos] = state.pos return end end end state.pos += 1 cache[pos] = state.pos end |
#tokenize(state) ⇒ Object
Generate tokens for input range
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/motion-markdown-it/parser_inline.rb', line 74 def tokenize(state) rules = @ruler.getRules('') len = rules.length end_pos = state.posMax maxNesting = state.md.[:maxNesting] while state.pos < end_pos # Try all possible rules. # On success, rule should: # # - update `state.pos` # - update `state.tokens` # - return true ok = false if state.level < maxNesting 0.upto(len - 1) do |i| ok = rules[i].call(state, false) break if ok end end if ok break if state.pos >= end_pos next end state.pending += state.src[state.pos] state.pos += 1 end unless state.pending.empty? state.pushPending end end |