Class: Metanorma::Standoc::NamedEscapePreprocessor

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

Instance Method Summary collapse

Instance Method Details

#convert(line, esc) ⇒ Object



64
65
66
67
68
# File 'lib/metanorma/standoc/macros.rb', line 64

def convert(line, esc)
  line.split(/(&[A-Za-z][^&;]*;)/).map do |s|
    /^&[A-Za-z]/.match?(s) ? esc.encode(esc.decode(s), :hexadecimal) : s
  end.join
end

#process(document, reader) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/metanorma/standoc/macros.rb', line 54

def process(document, reader)
  c = HTMLEntities.new
  p = Metanorma::Utils::LineStatus.new
  lines = reader.lines.map do |l|
    p.process(l)
    p.pass ? l : convert(l, c)
  end
  ::Asciidoctor::PreprocessorReader.new document, lines
end