2023-02-25 04:11:54 +00:00
|
|
|
class ManInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|
|
|
use_dsl
|
|
|
|
|
|
|
|
named :man
|
|
|
|
name_positional_attributes 'volnum'
|
2023-03-05 06:20:25 +00:00
|
|
|
default_attributes 'domain' => 'manpages.debian.org'
|
2023-02-25 04:11:54 +00:00
|
|
|
|
|
|
|
def process parent, target, attrs
|
|
|
|
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-05 06:20:25 +00:00
|
|
|
target = %(https://#{attrs['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
|