mirror of
https://github.com/foo-dogsquared/asciidoctor-foodogsquared-extensions.git
synced 2025-01-30 22:57:56 +00:00
Update man inline macro with fixed service types instead of domain
This commit is contained in:
parent
567c52d80a
commit
1b9ecedc60
@ -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.
|
The value from `volnum` attribute has higher precedence.
|
||||||
When both the positional argument and `volnum` attribute is passed, the `volnum` attribute will be used.
|
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.
|
- `service` is the domain of the online manpage service.
|
||||||
By default, it uses `manpages.debian.org`.
|
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
|
== Example usage
|
||||||
|
|
||||||
- `man:crontab[5]` will link to the default manpage service with `crontab(5)` manual page.
|
- `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].
|
||||||
|
@ -5,7 +5,7 @@ class ManInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|||||||
|
|
||||||
named :man
|
named :man
|
||||||
name_positional_attributes 'volnum'
|
name_positional_attributes 'volnum'
|
||||||
default_attributes 'domain' => 'manpages.debian.org'
|
default_attributes 'service' => 'debian'
|
||||||
|
|
||||||
def process(parent, target, attrs)
|
def process(parent, target, attrs)
|
||||||
doc = parent.document
|
doc = parent.document
|
||||||
@ -13,7 +13,18 @@ class ManInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|||||||
suffix = (volnum = attrs['volnum']) ? %((#{volnum})) : ''
|
suffix = (volnum = attrs['volnum']) ? %((#{volnum})) : ''
|
||||||
|
|
||||||
if doc.basebackend? 'html'
|
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
|
doc.register :links, target
|
||||||
node = create_anchor parent, text, type: :link, target: target
|
node = create_anchor parent, text, type: :link, target: target
|
||||||
elsif doc.backend == 'manpage'
|
elsif doc.backend == 'manpage'
|
||||||
|
Loading…
Reference in New Issue
Block a user