Class: MaRuKu::In::Markdown::SpanLevelParser::CaptureRule

Inherits:
Rule
  • Object
show all
Defined in:
lib/maruku/input/rubypants.rb

Overview

A more complex rule that uses a capture group from the pattern in its replacement.

Instance Attribute Summary

Attributes inherited from Rule

#doc, #pattern, #replacement

Instance Method Summary collapse

Methods inherited from Rule

#initialize

Constructor Details

This class inherits a constructor from MaRuKu::In::Markdown::SpanLevelParser::Rule

Instance Method Details

#apply(first, input, output) ⇒ Object

One at a time, replace each match, including some part of the match, and put the rest back into input to be processed next.



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/maruku/input/rubypants.rb', line 210

def apply(first, input, output)
  if pattern =~ first
    m = Regexp.last_match
    append_to_output(output, m.pre_match)
    input.unshift m.post_match unless m.post_match.empty?
    replacement.reverse_each do |sub|
      if sub == :one
        input.unshift m[1]
      else
        entity = sub.clone
        sub.doc = doc
        input.unshift entity
      end
    end
  else
    append_to_output(output, first)
  end
end