Class: Metanorma::Standoc::PseudocodeBlockMacro

Inherits:
Asciidoctor::Extensions::BlockProcessor
  • Object
show all
Defined in:
lib/metanorma/standoc/macros.rb

Instance Method Summary collapse

Instance Method Details

#init_indent(line) ⇒ Object



23
24
25
26
27
28
# File 'lib/metanorma/standoc/macros.rb', line 23

def init_indent(line)
  /^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ line
  prefix = prefix.gsub("\t", "\u00a0\u00a0\u00a0\u00a0")
    .gsub(/ /, "\u00a0")
  prefix + suffix
end

#process(parent, reader, attrs) ⇒ Object



44
45
46
47
48
49
# File 'lib/metanorma/standoc/macros.rb', line 44

def process(parent, reader, attrs)
  attrs["role"] = "pseudocode"
  lines = reader.lines.map { |m| init_indent(m) }
  create_block(parent, :example, supply_br(lines),
               attrs, content_model: :compound)
end

#supply_br(lines) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/metanorma/standoc/macros.rb', line 30

def supply_br(lines)
  ignore = false
  lines.each_with_index do |l, i|
    /^(--+|====+|\|===|\.\.\.\.+|\*\*\*\*+|\+\+\+\++|````+|____\+)$/
      .match(l) and (ignore = !ignore)
    next if l.empty? || l.match(/ \+$/) || /^\[.*\]$/.match?(l) ||
      ignore || i == lines.size - 1 ||
      (i < lines.size - 1 && lines[i + 1].empty?)

    lines[i] += " +"
  end
  lines
end