Class: Vivlio::Starter::CLI::PreProcessCommands::CrossReferenceProcessor::CaptionedBlockTransformer

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio/starter/cli/pre_process/cross_reference_processor.rb

Overview

キャプション付きブロック変換クラスrubocop:disable Metrics/ClassLength

Instance Method Summary collapse

Constructor Details

#initialize(content, filename, labels_map) ⇒ CaptionedBlockTransformer

Returns a new instance of CaptionedBlockTransformer.



336
337
338
339
340
341
# File 'lib/vivlio/starter/cli/pre_process/cross_reference_processor.rb', line 336

def initialize(content, filename, labels_map)
  @lines = content.lines
  @filename = filename
  @labels_map = labels_map
  @counters = Hash.new(0)
end

Instance Method Details

#transformObject



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/vivlio/starter/cli/pre_process/cross_reference_processor.rb', line 343

def transform
  output = []
  idx = 0
  in_code = false
  fence_marker = nil
  while idx < @lines.size
    line = @lines[idx]
    stripped = line.lstrip
    if (m = stripped.match(/\A(`{3,})/))
      fence = m[1]
      if in_code
        if fence == fence_marker
          in_code = false
          fence_marker = nil
        end
      else
        in_code = true
        fence_marker = fence
      end
      output << line
      idx += 1
      next
    end

    idx = in_code ? passthrough(output, idx) : process_line(output, idx)
  end
  output.join
end