Class: Asciidoctor::Foodogsquared::Extensions::SWHInlineMacro

Inherits:
Extensions::InlineMacroProcessor
  • Object
show all
Defined in:
lib/asciidoctor/foodogsquared/extensions/swhid-inline-macro.rb

Instance Method Summary collapse

Instance Method Details

#process(parent, target, attrs) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/asciidoctor/foodogsquared/extensions/swhid-inline-macro.rb', line 10

def process(parent, target, attrs)
  doc = parent.document

  # We're only considering `swh:` starting with the scheme version. Also, it
  # looks nice aesthetically.
  swhid = target.start_with?('swh:') ? target : %(swh:#{target})
  default_caption = if attrs.key? 'full-option'
                      swhid
                    else
                      swhid.split(';').at(0)
                    end
  text = attrs['caption'] || default_caption
  target = %(https://archive.softwareheritage.org/#{swhid})

  doc.register :links, target
  create_anchor parent, text, type: :link, target: target
end