| 1 |
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal' |
| 2 |
|
| 3 |
include Asciidoctor |
| 4 |
|
| 5 |
# An inline macro that generates links to related man pages. |
| 6 |
# For HTML it only generates links to Cockpit man pages as that is what |
| 7 |
# is compiled. But you are able to use man:systemd[1], but it just |
| 8 |
# won't get a link. |
| 9 |
# |
| 10 |
# Usage: |
| 11 |
# |
| 12 |
# man:gittutorial[7] |
| 13 |
# |
| 14 |
class ManInlineMacro < Extensions::InlineMacroProcessor |
| 15 |
use_dsl |
| 16 |
|
| 17 |
named :man |
| 18 |
name_positional_attributes 'volnum' |
| 19 |
|
| 20 |
def process parent, target, attrs |
| 21 |
text = manname = target |
| 22 |
suffix = '' |
| 23 |
volnum = attrs['volnum'] |
| 24 |
target = %(#{manname}.#{volnum}.html) |
| 25 |
suffix = %((#{volnum})) |
| 26 |
if parent.document.basebackend?('html') && manname.start_with?('cockpit') |
| 27 |
parent.document.register :links, target |
| 28 |
node = create_anchor parent, text, type: :link, target: target |
| 29 |
elsif parent.document.backend == 'manpage' |
| 30 |
node = create_inline parent, :quoted, manname, type: :strong |
| 31 |
else |
| 32 |
node = create_inline parent, :quoted, manname |
| 33 |
end |
| 34 |
suffix ? (create_inline parent, :quoted, %(#{node.convert}#{suffix})) : node |
| 35 |
end |
| 36 |
end |
| 37 |
|
| 38 |
Asciidoctor::Extensions.register do |
| 39 |
inline_macro ManInlineMacro |
| 40 |
end |