Method: JsDuck::InlineExamples#extract

Defined in:
lib/jsduck/inline_examples.rb

#extract(html) ⇒ Object

Extracts inline examples from HTML



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
# File 'lib/jsduck/inline_examples.rb', line 54

def extract(html)
  examples = []

  s = StringScanner.new(html)
  while !s.eos? do
    if s.check(/</)
      if s.check(@begin_example_re)

        s.scan(@begin_example_re) =~ @begin_example_re
        options = build_options_hash($1)

        ex = s.scan_until(@end_example_re).sub(@end_example_re, '')

        examples << {
          :code => Util::HTML.unescape(Util::HTML.strip_tags(ex)),
          :options => options,
        }
      else
        s.skip(/</)
      end
    else
      s.skip(/[^<]+/)
    end
  end

  examples
end