From 1b9ecedc6051bc2cbd5794738e44b2cc7c60b323 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 11 Mar 2023 16:34:48 +0800 Subject: [PATCH] Update man inline macro with fixed service types instead of domain --- lib/asciidoctor/man-inline-macro/README.adoc | 19 ++++++++++++++++--- lib/asciidoctor/man-inline-macro/extension.rb | 15 +++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/asciidoctor/man-inline-macro/README.adoc b/lib/asciidoctor/man-inline-macro/README.adoc index ce0ed01..22d4962 100644 --- a/lib/asciidoctor/man-inline-macro/README.adoc +++ b/lib/asciidoctor/man-inline-macro/README.adoc @@ -22,12 +22,25 @@ This attribute is another way to indicate the section in case you start to use m The value from `volnum` attribute has higher precedence. When both the positional argument and `volnum` attribute is passed, the `volnum` attribute will be used. -- `domain` is the domain of the online manpage service. -By default, it uses `manpages.debian.org`. +- `service` is the domain of the online manpage service. +Take note this attribute is only used in `html` backend. ++ +-- +This is an attribute that expects certain values: + +- `debian` uses https://manpages.debian.org. +This is also the default service when no value is given. + +- `archlinux` uses https://man.archlinux.org. + +- `opensuse` uses https://manpages.opensuse.org. + +Any invalid value raises an error. +-- == Example usage - `man:crontab[5]` will link to the default manpage service with `crontab(5)` manual page. -- `man:man[volnum=1, domain=man.archlinux.org/man]` will link to the link:https://man.archlinux.org/man/man.1[man manpage] from link:https://man.archlinux.org/[man.archlinux.org]. +- `man:man[volnum=1, service=archlinux]` will link to the link:https://man.archlinux.org/man/man.1[man manpage] from link:https://man.archlinux.org/[man.archlinux.org]. diff --git a/lib/asciidoctor/man-inline-macro/extension.rb b/lib/asciidoctor/man-inline-macro/extension.rb index 8fe4142..fcdd79a 100644 --- a/lib/asciidoctor/man-inline-macro/extension.rb +++ b/lib/asciidoctor/man-inline-macro/extension.rb @@ -5,7 +5,7 @@ class ManInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor named :man name_positional_attributes 'volnum' - default_attributes 'domain' => 'manpages.debian.org' + default_attributes 'service' => 'debian' def process(parent, target, attrs) doc = parent.document @@ -13,7 +13,18 @@ class ManInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor suffix = (volnum = attrs['volnum']) ? %((#{volnum})) : '' if doc.basebackend? 'html' - target = %(https://#{attrs['domain']}/#{manname}.#{volnum}) + 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/' + 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 elsif doc.backend == 'manpage'