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

#log(doc, text) ⇒ Object

debugging output of results of all preprocessing, including include files concatenation and Lutaml/Liquid processing



72
73
74
75
76
77
78
79
80
# File 'lib/metanorma/standoc/macros.rb', line 72

def log(doc, text)
  source = doc.attr("docfile") || "metanorma"
  dirname  = File.dirname(source)
  basename = File.basename(source, ".*")
  fname = File.join(dirname, "#{basename}.asciidoc.log.txt")
  File.open(fname, "w:UTF-8") do |f|
    f.write(text.join("\n"))
  end
end

#process(document, reader) ⇒ Object



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

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
  log(document, lines)
  ::Asciidoctor::PreprocessorReader.new document, lines
end