Class: Metanorma::Standoc::ConceptInlineMacro
- Inherits:
-
Asciidoctor::Extensions::InlineMacroProcessor
- Object
- Asciidoctor::Extensions::InlineMacroProcessor
- Metanorma::Standoc::ConceptInlineMacro
- Defined in:
- lib/metanorma/standoc/macros_terms.rb
Overview
Possibilities: term} term, text} term} term, text} {term} equivalent to term: text} equivalent to term:[term, text] text may optionally be followed by crossreference-rendering, options=“”
Instance Method Summary collapse
- #generate_attrs(opts) ⇒ Object
- #preprocess_attrs(target) ⇒ Object
- #preprocess_attrs_csv(line) ⇒ Object
- #process(parent, target, _attrs) ⇒ Object
Instance Method Details
#generate_attrs(opts) ⇒ Object
130 131 132 133 134 135 136 137 |
# File 'lib/metanorma/standoc/macros_terms.rb', line 130 def generate_attrs(opts) ret = "" %w(ital bold ref linkmention linkref).each do |x| opts.include?("no#{x}") and ret += " #{x}='false'" opts.include?(x) and ret += " #{x}='true'" end ret end |
#preprocess_attrs(target) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/metanorma/standoc/macros_terms.rb', line 109 def preprocess_attrs(target) m = /^(?<id><<.+?>>)?(?<rest>.*)$/m.match(target) ret = { id: m[:id]&.sub(/^<</, "")&.sub(/>>$/, "") } if m2 = /^(?<rest>.*?)(?<opt>,opt(?:ion)?s=.+)$/m .match(m[:rest].sub(/^,/, "")) ret[:opt] = CSV.parse_line(m2[:opt].sub(/^,opt(ion)?s=/, "") .sub(/^"(.+)"$/m, "\\1").sub(/^'(.+)'$/m, "\\1")) attrs = preprocess_attrs_csv(m2[:rest]) else attrs = preprocess_attrs_csv(m[:rest]) end attrs.map! { |x| x.gsub(/\s+/, " ") } ret.merge(term: attrs[0], word: attrs[1] || attrs[0], render: attrs[2]) end |
#preprocess_attrs_csv(line) ⇒ Object
124 125 126 127 128 |
# File 'lib/metanorma/standoc/macros_terms.rb', line 124 def preprocess_attrs_csv(line) CSV.parse_line(line.sub(/^,/, "")) || [] rescue StandardError raise "error processing #{line} as CSV" end |
#process(parent, target, _attrs) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/metanorma/standoc/macros_terms.rb', line 139 def process(parent, target, _attrs) attrs = preprocess_attrs(target) term, word, render = %i(term word render).each_with_object([]) do |x, m| m << Asciidoctor::Inline.new(parent, :quoted, attrs[x]).convert end opt = generate_attrs(attrs[:opt] || []) if attrs[:id] then "<concept#{opt} key='#{attrs[:id]}'><refterm>" \ "#{term}</refterm><renderterm>#{word}</renderterm>" \ "<xrefrender>#{render}</xrefrender></concept>" else "<concept#{opt}><termxref>#{term}</termxref><renderterm>" \ "#{word}</renderterm><xrefrender>#{render}</xrefrender></concept>" end rescue StandardError => e raise("processing {{#{target}}}: #{e.}") end |