Class: Asciidoctor::Foodogsquared::Extensions::ManInlineMacro

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

Instance Method Summary collapse

Instance Method Details

#process(parent, target, attrs) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/asciidoctor/foodogsquared/extensions/man-inline-macro.rb', line 11

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

  text = %(#{manname}(#{attrs['volnum']}))

  if doc.basebackend? 'html'
    domain = case attrs['service']
             when 'debian'
               'https://manpages.debian.org'
             when 'ubuntu'
               'https://manpages.ubuntu.org'
             when 'arch'
               'https://man.archlinux.org/man'
             when 'opensuse'
               'https://manpages.opensuse.org'
             when 'voidlinux'
               'https://man.voidlinux.org'
             when 'openbsd'
               'https://man.openbsd.org'
             when 'none'
               nil
             else
               raise "no available manpage service #{attrs['service']}"
             end

    subpath = "#{attrs['subpath'].delete_prefix('/').delete_suffix('/')}/" if !attrs['subpath'].empty?
    if !domain.nil?
      target = %(#{domain}/#{subpath}#{manname}.#{attrs['volnum']})
      doc.register :links, target
      node = create_anchor parent, text, type: :link, target: target
    else
      node = create_inline parent, :quoted, text
    end
  elsif doc.backend == 'manpage'
    node = create_inline parent, :quoted, text, type: :strong
  else
    node = create_inline parent, :quoted, text
  end

  node
end