Class: Asciidoctor::Standoc::ConceptInlineMacro

Inherits:
Extensions::InlineMacroProcessor
  • Object
show all
Defined in:
lib/asciidoctor/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

Instance Method Details

#preprocess_attrs(target) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/asciidoctor/standoc/macros_terms.rb', line 68

def preprocess_attrs(target)
  m = /^(?<id>&lt;&lt;.+?&gt;&gt;)?(?<rest>.*)$/.match(target)
  ret = { id: m[:id]&.sub(/^&lt;&lt;/, "")&.sub(/&gt;&gt;$/, "") }
  m2 = /^(?<rest>.*)(?<opt>,option=.+)?$/.match(m[:rest].sub(/^,/, ""))
  ret[:opt] = m2[:opt]&.sub(/^,option=/, "")
  attrs = CSV.parse_line(m2[:rest]) || []
  ret.merge(term: attrs[0], word: attrs[1] || attrs[0],
            xrefrender: attrs[2])
end

#process(parent, target, _attrs) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/asciidoctor/standoc/macros_terms.rb', line 78

def process(parent, target, _attrs)
  attrs = preprocess_attrs(target)
  termout = Asciidoctor::Inline.new(parent, :quoted, attrs[:term]).convert
  wordout = Asciidoctor::Inline.new(parent, :quoted, attrs[:word]).convert
  xrefout = Asciidoctor::Inline.new(parent, :quoted,
                                    attrs[:xrefrender]).convert
  attrs[:id] and return "<concept key='#{attrs[:id]}'><refterm>"\
    "#{termout}</refterm><renderterm>#{wordout}</renderterm>"\
    "<xrefrender>#{xrefout}</xrefrender></concept>"
  "<concept><termxref>#{termout}</termxref><renderterm>#{wordout}"\
    "</renderterm><xrefrender>#{xrefout}</xrefrender></concept>"
end