Class: Metanorma::Standoc::IndexXrefInlineMacro

Inherits:
Asciidoctor::Extensions::InlineMacroProcessor
  • Object
show all
Defined in:
lib/metanorma/standoc/macros_link.rb

Instance Method Summary collapse

Instance Method Details

#preprocess_attrs(attrs) ⇒ Object



7
8
9
10
11
12
# File 'lib/metanorma/standoc/macros_link.rb', line 7

def preprocess_attrs(attrs)
  ret = { primary: attrs[1], target: attrs[attrs.size] }
  ret[:secondary] = attrs[2] if attrs.size > 2
  ret[:tertiary] = attrs[3] if attrs.size > 3
  ret
end

#process(parent, target, attr) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/metanorma/standoc/macros_link.rb', line 22

def process(parent, target, attr)
  validate(parent, target, attr) or return
  args = preprocess_attrs(attr)
  ret = "<index-xref also='#{target == 'also'}'>" \
        "<primary>#{args[:primary]}</primary>"
  ret += "<secondary>#{args[:secondary]}</secondary>" if args[:secondary]
  ret += "<tertiary>#{args[:tertiary]}</tertiary>" if args[:tertiary]
  ret + "<target>#{args[:target]}</target></index-xref>"
end

#validate(parent, target, attrs) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/metanorma/standoc/macros_link.rb', line 14

def validate(parent, target, attrs)
  attrs.size > 1 && attrs.size < 5 and return true
  e = "invalid index \"#{target}\" cross-reference: wrong number of " \
      "attributes in `index:#{target}[#{attrs.values.join(',')}]`"
  parent.converter.log.add("Crossreferences", parent, e, severity: 0)
  false
end