Class: Asciidoctor::Standoc::ConceptInlineMacro
- Inherits:
-
Extensions::InlineMacroProcessor
- Object
- Extensions::InlineMacroProcessor
- Asciidoctor::Standoc::ConceptInlineMacro
- 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
- #generate_attrs(opts) ⇒ Object
- #preprocess_attrs(target) ⇒ Object
- #process(parent, target, _attrs) ⇒ Object
Instance Method Details
#generate_attrs(opts) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/asciidoctor/standoc/macros_terms.rb', line 95 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'" ret end |
#preprocess_attrs(target) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/asciidoctor/standoc/macros_terms.rb', line 81 def preprocess_attrs(target) m = /^(?<id><<.+?>>)?(?<rest>.*)$/.match(target) ret = { id: m[:id]&.sub(/^<</, "")&.sub(/>>$/, "") } if m2 = /^(?<rest>.*?)(?<opt>,option=.+)$/.match(m[:rest].sub(/^,/, "")) ret[:opt] = CSV.parse_line(m2[:opt].sub(/^,option=/, "") .sub(/^"(.+)"$/, "\\1").sub(/^'(.+)'$/, "\\1")) attrs = CSV.parse_line(m2[:rest]) || [] else attrs = CSV.parse_line(m[:rest].sub(/^,/, "")) || [] end ret.merge(term: attrs[0], word: attrs[1] || attrs[0], xrefrender: attrs[2]) end |
#process(parent, target, _attrs) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/asciidoctor/standoc/macros_terms.rb', line 104 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 optout = generate_attrs(attrs[:opt] || []) attrs[:id] and return "<concept#{optout} key='#{attrs[:id]}'><refterm>"\ "#{termout}</refterm><renderterm>#{wordout}</renderterm>"\ "<xrefrender>#{xrefout}</xrefrender></concept>" "<concept#{optout}><termxref>#{termout}</termxref><renderterm>"\ "#{wordout}</renderterm><xrefrender>#{xrefout}</xrefrender></concept>" end |