Module: Coradoc::IncludeSelectors::LevelOffset

Defined in:
lib/coradoc/include_selectors/level_offset.rb

Overview

Shifts section heading levels in a parsed CoreModel subtree.

Applied AFTER parsing — works on SectionElement instances. Two modes:

relative (+N / -N)   every SectionElement#level += delta
absolute (N)         the FIRST section's level becomes N, and
                      descendants shift by the same delta so their
                      relative structure is preserved (asciidoctor
                      behavior).

The processor passes a freshly-parsed subtree to this selector, so there are no external references and in-place mutation is safe.

Class Method Summary collapse

Class Method Details

.call(core, options:) ⇒ Coradoc::CoreModel::Base

Returns the same core (mutated).

Parameters:

Returns:



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/coradoc/include_selectors/level_offset.rb', line 21

def self.call(core, options:)
  offset = options.leveloffset
  return core if offset.nil?

  first_level = find_first_level(core)
  actual_delta = compute_actual_delta(offset, first_level)
  return core if actual_delta.zero?

  walk_and_shift(core, actual_delta)
  core
end