-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathextension.rb
34 lines (30 loc) · 919 Bytes
/
extension.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
include Asciidoctor
# An inline macro that generates links to related man pages.
#
# Usage:
#
# man:gittutorial[7]
#
class ManInlineMacro < Extensions::InlineMacroProcessor
use_dsl
named :man
name_positional_attributes 'volnum'
def process parent, target, attrs
text = manname = target
suffix = ''
target = %(#{manname}.html)
if (volnum = attrs['volnum'])
suffix = %((#{volnum}))
end
if parent.document.basebackend? 'html'
parent.document.register :links, target
node = create_anchor parent, text, type: :link, target: target
elsif parent.document.backend == 'manpage'
node = create_inline parent, :quoted, manname, type: :strong
else
node = create_inline parent, :quoted, manname
end
suffix ? (create_inline parent, :quoted, %(#{node.convert}#{suffix})) : node
end
end