class Metanorma::Standoc::ConceptInlineMacro
Possibilities: {{<<id>>, term}} {{<<id>>, term, text}} {{<<termbase:id>>, term}} {{<<termbase:id>>, term, text}} {{term}} equivalent to term: {{term, text}} equivalent to term:[term, text] text may optionally be followed by crossreference-rendering, options=“”
Public Instance Methods
generate_attrs(opts)
click to toggle source
# File lib/metanorma/standoc/macros_terms.rb, line 132 def generate_attrs(opts) ret = "" opts.include?("noital") and ret += " ital='false'" opts.include?("noref") and ret += " ref='false'" opts.include?("ital") and ret += " ital='true'" opts.include?("ref") and ret += " ref='true'" opts.include?("nolinkmention") and ret += " linkmention='false'" opts.include?("linkmention") and ret += " linkmention='true'" opts.include?("nolinkref") and ret += " linkref='false'" opts.include?("linkref") and ret += " linkref='true'" ret end
preprocess_attrs(target)
click to toggle source
# File lib/metanorma/standoc/macros_terms.rb, line 109 def preprocess_attrs(target) m = /^(?<id><<.+?>>)?(?<rest>.*)$/.match(target) ret = { id: m[:id]&.sub(/^<</, "")&.sub(/>>$/, "") } if m2 = /^(?<rest>.*?)(?<opt>,opt(ion)?s=.+)$/ .match(m[:rest].sub(/^,/, "")) ret[:opt] = CSV.parse_line(m2[:opt].sub(/^,opt(ion)?s=/, "") .sub(/^"(.+)"$/, "\\1").sub(/^'(.+)'$/, "\\1")) begin attrs = CSV.parse_line(m2[:rest]) || [] rescue StandardError raise "error processing #{m2[:rest]} as CSV" end else begin attrs = CSV.parse_line(m[:rest].sub(/^,/, "")) || [] rescue StandardError raise "error processing #{m[:rest]} as CSV" end end ret.merge(term: attrs[0], word: attrs[1] || attrs[0], render: attrs[2]) end
process(parent, target, _attrs)
click to toggle source
# File lib/metanorma/standoc/macros_terms.rb, line 145 def process(parent, target, _attrs) attrs = preprocess_attrs(target) term = Asciidoctor::Inline.new(parent, :quoted, attrs[:term]).convert word = Asciidoctor::Inline.new(parent, :quoted, attrs[:word]).convert xref = Asciidoctor::Inline.new(parent, :quoted, attrs[:render]).convert opt = generate_attrs(attrs[:opt] || []) if attrs[:id] then "<concept#{opt} key='#{attrs[:id]}'><refterm>"\ "#{term}</refterm><renderterm>#{word}</renderterm>"\ "<xrefrender>#{xref}</xrefrender></concept>" else "<concept#{opt}><termxref>#{term}</termxref><renderterm>"\ "#{word}</renderterm><xrefrender>#{xref}</xrefrender></concept>" end rescue StandardError => e raise("processing {{#{target}}}: #{e.message}") end