Class: Metanorma::Standoc::PassProtectPreprocessor

Inherits:
LinkProtectPreprocessor show all
Defined in:
lib/metanorma/standoc/macros.rb

Overview

convert pass:[] to pass-format:metanorma[]

Constant Summary

Constants inherited from LinkProtectPreprocessor

LinkProtectPreprocessor::BRACKETS, LinkProtectPreprocessor::InlineLinkMacroRx, LinkProtectPreprocessor::InlineLinkMacroRx1, LinkProtectPreprocessor::InlineLinkRx, LinkProtectPreprocessor::PASS_INLINE_MACROS, LinkProtectPreprocessor::PASS_INLINE_MACRO_RX, LinkProtectPreprocessor::PASS_INLINE_MACRO_STR

Instance Method Summary collapse

Methods inherited from LinkProtectPreprocessor

#inlinelink_escape, #inlinelinkmacro, #linkcontents_escape

Instance Method Details



237
238
239
240
# File 'lib/metanorma/standoc/macros.rb', line 237

def inlinelink(text)
  /^\[.*\]\s*$/.match?(text) and return text
  pass_inline_split(text).join
end

#pass_convert(text) ⇒ Object

pass: => pass-format:metanorma[A], so long as A doesn’t already start with ++ ditto pass-format: => pass-format:[A] convert any ] in the ... body to ]



225
226
227
228
229
230
231
232
233
234
235
# File 'lib/metanorma/standoc/macros.rb', line 225

def pass_convert(text)
  text
    .gsub(/pass-format:([^\[ ]*)\[(?!\+\+)(.+?)(?<!\\)\]/) do |_m|
    "pass-format:#{$1}[++#{$2.gsub(/\\\]/, ']')}++]"
  end
    .gsub(/pass:\[(?=\+\+)(.+?)(?<!\\)\]/,
          "pass-format:metanorma[\\1]")
    .gsub(/pass:\[(?!\+\+)(.+?)(?<!\\)\]/) do |_m|
    "pass-format:metanorma[++#{$1.gsub(/\\\]/, ']')}++]"
  end
end

#pass_inline_split(text) ⇒ Object



215
216
217
218
219
# File 'lib/metanorma/standoc/macros.rb', line 215

def pass_inline_split(text)
  text.split(PASS_INLINE_MACRO_RX).each.map do |x|
    PASS_INLINE_MACRO_RX.match?(x) ? pass_convert(x) : x
  end
end

#process(document, reader) ⇒ Object



204
205
206
207
208
209
210
211
212
213
# File 'lib/metanorma/standoc/macros.rb', line 204

def process(document, reader)
  p = Metanorma::Utils::LineStatus.new
  lines = reader.lines.map do |t|
    p.process(t)
    !p.pass && (t.include?("pass:") || t.include?("pass-format:")) and
      t = inlinelink(t)
    t
  end
  ::Asciidoctor::PreprocessorReader.new document, lines
end