Add test and improve handling of subpath for man inline macro

This commit is contained in:
Gabriel Arazas 2023-11-07 19:35:29 +08:00
parent 9d3f69be6e
commit 2977870311
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
2 changed files with 13 additions and 1 deletions

View File

@ -34,8 +34,9 @@ module Asciidoctor::Foodogsquared::Extensions
raise "no available manpage service #{attrs['service']}"
end
subpath = "#{attrs['subpath'].delete_prefix('/').delete_suffix('/')}/" if !attrs['subpath'].empty?
if !domain.nil?
target = %(#{domain}/#{attrs['subpath'].delete_prefix '/'}#{manname}.#{attrs['volnum']})
target = %(#{domain}/#{subpath}#{manname}.#{attrs['volnum']})
doc.register :links, target
node = create_anchor parent, text, type: :link, target: target
else

View File

@ -12,6 +12,17 @@ describe ManInlineMacro do
(expect actual).to include expected.chomp
end
it 'should process with the Debian Bookworm section' do
input = 'man:ls[1, service=debian, subpath=/bookworm]'
expected = <<~RESULT
<a href="https://manpages.debian.org/bookworm/ls.1">ls(1)</a>
RESULT
actual = (Asciidoctor.convert input).tr_s '\n', '\n'
(expect actual).to include expected.chomp
end
it 'should link to the Arch Linux manpage' do
input = 'man:ls[volnum=1, service=arch]'