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
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/asciidoctor/standoc/macros_terms.rb', line 104 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) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# 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>,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) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/asciidoctor/standoc/macros_terms.rb', line 117 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.}") end |