Class: Metanorma::Standoc::PassProtectPreprocessor
- Inherits:
-
LinkProtectPreprocessor
- Object
- Asciidoctor::Extensions::Preprocessor
- LinkProtectPreprocessor
- Metanorma::Standoc::PassProtectPreprocessor
- Defined in:
- lib/metanorma/converter/macros_nosub.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
- #inlinelink(text) ⇒ Object
-
#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 ]. - #pass_inline_split(text) ⇒ Object
- #process(document, reader) ⇒ Object
Methods inherited from LinkProtectPreprocessor
#inlinelink_escape, #inlinelinkmacro, #linkcontents_escape
Instance Method Details
#inlinelink(text) ⇒ Object
210 211 212 213 |
# File 'lib/metanorma/converter/macros_nosub.rb', line 210 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 ]
198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/metanorma/converter/macros_nosub.rb', line 198 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
188 189 190 191 192 |
# File 'lib/metanorma/converter/macros_nosub.rb', line 188 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
177 178 179 180 181 182 183 184 185 186 |
# File 'lib/metanorma/converter/macros_nosub.rb', line 177 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 |