From ff59ce0fca84e2d969994cbbea74e2546be08986 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Fri, 7 Apr 2023 06:25:19 +0800 Subject: [PATCH] Add `voidlinux` and `none` for possible services in man inline macro --- lib/asciidoctor/man-inline-macro/README.adoc | 5 +++ lib/asciidoctor/man-inline-macro/extension.rb | 36 +++++++++++-------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/asciidoctor/man-inline-macro/README.adoc b/lib/asciidoctor/man-inline-macro/README.adoc index 22d4962..9b4d763 100644 --- a/lib/asciidoctor/man-inline-macro/README.adoc +++ b/lib/asciidoctor/man-inline-macro/README.adoc @@ -35,6 +35,11 @@ This is also the default service when no value is given. - `opensuse` uses https://manpages.opensuse.org. +- `voidlinux` use https://man.voidlinux.org. + +- `none` uses none at all. :) +This is useful if the reference is not found anywhere. + Any invalid value raises an error. -- diff --git a/lib/asciidoctor/man-inline-macro/extension.rb b/lib/asciidoctor/man-inline-macro/extension.rb index 1d3209d..7e67923 100644 --- a/lib/asciidoctor/man-inline-macro/extension.rb +++ b/lib/asciidoctor/man-inline-macro/extension.rb @@ -13,22 +13,28 @@ class ManInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor suffix = (volnum = attrs['volnum']) ? %((#{volnum})) : '' if doc.basebackend? 'html' - case attrs['service'] - when 'debian' - domain = 'https://manpages.debian.org' - when 'arch' - domain = 'https://man.archlinux.org/man' - when 'opensuse' - domain = 'https://manpages.opensuse.org' - when 'voidlinux' - domain = 'https://man.voidlinux.org' - else - raise "no available manpage service #{attrs['service']}" - end + domain = case attrs['service'] + when 'debian' + 'https://manpages.debian.org' + when 'arch' + 'https://man.archlinux.org/man' + when 'opensuse' + 'https://manpages.opensuse.org' + when 'voidlinux' + 'https://man.voidlinux.org' + when 'none' + nil + else + raise "no available manpage service #{attrs['service']}" + end - target = %(#{domain}/#{manname}.#{volnum}) - doc.register :links, target - node = create_anchor parent, text, type: :link, target: target + if !domain.nil? + target = %(#{domain}/#{manname}.#{volnum}) + doc.register :links, target + node = create_anchor parent, text, type: :link, target: target + else + node = create_inline parent, :quoted, manname + end elsif doc.backend == 'manpage' node = create_inline parent, :quoted, manname, type: :strong else