Class: Asciidoctor::Standoc::PseudocodeBlockMacro
- Inherits:
-
Extensions::BlockProcessor
- Object
- Extensions::BlockProcessor
- Asciidoctor::Standoc::PseudocodeBlockMacro
- Defined in:
- lib/asciidoctor/standoc/macros.rb
Instance Method Summary collapse
- #init_indent(s) ⇒ Object
- #prevent_smart_quotes(m) ⇒ Object
- #process(parent, reader, attrs) ⇒ Object
- #supply_br(lines) ⇒ Object
Instance Method Details
#init_indent(s) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/asciidoctor/standoc/macros.rb', line 78 def init_indent(s) /^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ s prefix = prefix.gsub(/\t/, "\u00a0\u00a0\u00a0\u00a0"). gsub(/ /, "\u00a0") prefix + suffix end |
#prevent_smart_quotes(m) ⇒ Object
94 95 96 |
# File 'lib/asciidoctor/standoc/macros.rb', line 94 def prevent_smart_quotes(m) m.gsub(/'/, "'").gsub(/"/, """) end |
#process(parent, reader, attrs) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/asciidoctor/standoc/macros.rb', line 98 def process parent, reader, attrs attrs['role'] = 'pseudocode' lines = reader.lines.map { |m| prevent_smart_quotes(init_indent(m)) } create_block(parent, :example, supply_br(lines), attrs, content_model: :compound) end |
#supply_br(lines) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/asciidoctor/standoc/macros.rb', line 85 def supply_br(lines) lines.each_with_index do |l, i| next if l.empty? || l.match(/ \+$/) next if i == lines.size - 1 || i < lines.size - 1 && lines[i+1].empty? lines[i] += " +" end lines end |