Class: Asciidoctor::Standoc::PseudocodeBlockMacro
- Inherits:
-
Extensions::BlockProcessor
- Object
- Extensions::BlockProcessor
- Asciidoctor::Standoc::PseudocodeBlockMacro
- Defined in:
- lib/asciidoctor/standoc/macros.rb
Instance Method Summary collapse
Instance Method Details
#init_indent(s) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/asciidoctor/standoc/macros.rb', line 65 def init_indent(s) /^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ s prefix = prefix.gsub(/\t/, "\u00a0\u00a0\u00a0\u00a0") .gsub(/ /, "\u00a0") prefix + suffix end |
#process(parent, reader, attrs) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/asciidoctor/standoc/macros.rb', line 86 def process(parent, reader, attrs) attrs["role"] = "pseudocode" lines = reader.lines.map { |m| init_indent(m) } ret = create_block(parent, :example, supply_br(lines), attrs, content_model: :compound) ret end |
#supply_br(lines) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/asciidoctor/standoc/macros.rb', line 72 def supply_br(lines) ignore = false lines.each_with_index do |l, i| /^(--+|====+|\|===|\.\.\.\.+|\*\*\*\*+|\+\+\+\++|\`\`\`\`+|____\+)$/.match(l) && (ignore = !ignore) next if l.empty? || l.match(/ \+$/) next if /^\[.*\]$/.match(l) next if ignore next if i == lines.size - 1 || i < lines.size - 1 && lines[i + 1].empty? lines[i] += " +" end lines end |