Class: Metanorma::Standoc::PseudocodeBlockMacro
- Inherits:
-
Asciidoctor::Extensions::BlockProcessor
- Object
- Asciidoctor::Extensions::BlockProcessor
- Metanorma::Standoc::PseudocodeBlockMacro
- Defined in:
- lib/metanorma/standoc/macros.rb
Instance Method Summary collapse
Instance Method Details
#init_indent(line) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/metanorma/standoc/macros.rb', line 24 def init_indent(line) /^(?<prefix>[ \t]*)(?![ \t])(?<suffix>.*)$/ =~ line prefix = prefix.gsub("\t", "\u00a0\u00a0\u00a0\u00a0") .tr(" ", "\u00a0") prefix + suffix end |
#process(parent, reader, attrs) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/metanorma/standoc/macros.rb', line 45 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
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/metanorma/standoc/macros.rb', line 31 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 |