Class: Metanorma::Standoc::NamedEscapePreprocessor
- Inherits:
-
Asciidoctor::Extensions::Preprocessor
- Object
- Asciidoctor::Extensions::Preprocessor
- Metanorma::Standoc::NamedEscapePreprocessor
- Defined in:
- lib/metanorma/converter/macros.rb
Instance Method Summary collapse
-
#convert(line, esc) ⇒ Object
Only recognise HTML named entity references, whose name is
[A-Za-z][A-Za-z0-9]*. -
#log(doc, text) ⇒ Object
debugging output of results of all preprocessing, including include files concatenation and Lutaml/Liquid processing.
- #process(document, reader) ⇒ Object
Instance Method Details
#convert(line, esc) ⇒ Object
Only recognise HTML named entity references, whose name is
[A-Za-z][A-Za-z0-9]*. The character class must exclude whitespace and
<, otherwise a stray unspaced &X swallows text up to the next ; on
the line -- e.g. the ; connective separator inside an and!/to!
crossreference range -- corrupting the <<...>> and dropping the xref.
metanorma/isodoc#839
70 71 72 73 74 |
# File 'lib/metanorma/converter/macros.rb', line 70 def convert(line, esc) line.split(/(&[A-Za-z][A-Za-z0-9]*;)/).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.
Skipped for docfile-less (string/stdin) input: the target would degenerate to a single CWD-relative "./metanorma.asciidoc.log.txt" that the thousands of collection sub-compiles all truncate-rewrite (so it carries no useful diagnostics anyway). And a diagnostic write must never abort the build, so a write failure degrades to a warning rather than propagating out of the preprocessor. metanorma/metanorma-standoc#1209
85 86 87 88 89 90 91 92 93 |
# File 'lib/metanorma/converter/macros.rb', line 85 def log(doc, text) source = doc.attr("docfile") or return dirname = File.dirname(source) basename = File.basename(source, ".*") fname = File.join(dirname, "#{basename}.asciidoc.log.txt") File.open(fname, "w:UTF-8") { |f| f.write(text.join("\n")) } rescue SystemCallError => e warn "metanorma: could not write preprocessing log #{fname}: #{e.}" end |
#process(document, reader) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/metanorma/converter/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 |