Class: Jekyll::Stepper::Converter
- Inherits:
-
Object
- Object
- Jekyll::Stepper::Converter
- Defined in:
- lib/jekyll-stepper/converter.rb
Instance Method Summary collapse
- #convert(content) ⇒ Object
-
#initialize(config) ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
#initialize(config) ⇒ Converter
Returns a new instance of Converter.
6 7 8 |
# File 'lib/jekyll-stepper/converter.rb', line 6 def initialize(config) @config = config end |
Instance Method Details
#convert(content) ⇒ Object
10 11 12 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 |
# File 'lib/jekyll-stepper/converter.rb', line 10 def convert(content) lines = content.lines result = [] i = 0 while i < lines.length line = lines[i] match = line.match(/^(`{3,})(\S*)\s*$/) if match backtick_count = match[1].length info_string = match[2] if info_string == "stepper" block_lines = [] i += 1 closer = /^`{#{backtick_count}}\s*$/ while i < lines.length break if lines[i].match(closer) block_lines << lines[i] i += 1 end i += 1 if i < lines.length steps = parse_steps(block_lines.join) if steps.empty? result << "#{match[1]}stepper\n" result.concat(block_lines) result << "`" * backtick_count + "\n" else result << render_stepper(steps) end else result << line i += 1 closer = /^`{#{backtick_count}}\s*$/ while i < lines.length result << lines[i] break if lines[i].match(closer) i += 1 end i += 1 end else result << line i += 1 end end result.join end |