From 2977870311007b2e4e88a3cc5b3e01c0185c926c Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Tue, 7 Nov 2023 19:35:29 +0800 Subject: [PATCH] Add test and improve handling of subpath for man inline macro --- .../foodogsquared/man-inline-macro/extension.rb | 3 ++- spec/man_inline_macro_spec.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/asciidoctor/foodogsquared/man-inline-macro/extension.rb b/lib/asciidoctor/foodogsquared/man-inline-macro/extension.rb index aba87b7..0246045 100644 --- a/lib/asciidoctor/foodogsquared/man-inline-macro/extension.rb +++ b/lib/asciidoctor/foodogsquared/man-inline-macro/extension.rb @@ -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 diff --git a/spec/man_inline_macro_spec.rb b/spec/man_inline_macro_spec.rb index 2c26dfb..5268c28 100644 --- a/spec/man_inline_macro_spec.rb +++ b/spec/man_inline_macro_spec.rb @@ -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 + ls(1) + 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]'