2023-03-06 17:04:21 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-02-25 04:11:54 +00:00
|
|
|
class ManInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|
|
|
use_dsl
|
|
|
|
|
|
|
|
named :man
|
|
|
|
name_positional_attributes 'volnum'
|
2023-03-11 08:34:48 +00:00
|
|
|
default_attributes 'service' => 'debian'
|
2023-02-25 04:11:54 +00:00
|
|
|
|
2023-03-06 17:04:21 +00:00
|
|
|
def process(parent, target, attrs)
|
2023-02-25 04:11:54 +00:00
|
|
|
doc = parent.document
|
|
|
|
text = manname = target
|
|
|
|
suffix = (volnum = attrs['volnum']) ? %((#{volnum})) : ''
|
2023-03-05 06:20:25 +00:00
|
|
|
|
2023-02-25 04:11:54 +00:00
|
|
|
if doc.basebackend? 'html'
|
2023-03-11 08:34:48 +00:00
|
|
|
case attrs['service']
|
|
|
|
when 'debian'
|
2023-03-12 02:25:13 +00:00
|
|
|
domain = 'https://manpages.debian.org'
|
2023-03-11 08:34:48 +00:00
|
|
|
when 'arch'
|
|
|
|
domain = 'https://man.archlinux.org/man'
|
|
|
|
when 'opensuse'
|
2023-03-12 02:25:13 +00:00
|
|
|
domain = 'https://manpages.opensuse.org'
|
2023-03-23 06:29:38 +00:00
|
|
|
when 'voidlinux'
|
|
|
|
domain = 'https://man.voidlinux.org'
|
2023-03-11 08:34:48 +00:00
|
|
|
else
|
|
|
|
raise "no available manpage service #{attrs['service']}"
|
|
|
|
end
|
|
|
|
|
|
|
|
target = %(#{domain}/#{manname}.#{volnum})
|
2023-02-25 04:11:54 +00:00
|
|
|
doc.register :links, target
|
|
|
|
node = create_anchor parent, text, type: :link, target: target
|
|
|
|
elsif doc.backend == 'manpage'
|
|
|
|
node = create_inline parent, :quoted, manname, type: :strong
|
|
|
|
else
|
|
|
|
node = create_inline parent, :quoted, manname
|
|
|
|
end
|
|
|
|
create_inline parent, :quoted, %(#{node.convert}#{suffix})
|
|
|
|
end
|
|
|
|
end
|