-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathasciidoctor-extensions.rb
48 lines (37 loc) · 1.28 KB
/
asciidoctor-extensions.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'asciidoctor'
require 'asciidoctor/extensions'
class PrInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
use_dsl
named :pr
def process parent, target, attrs
pr = target
target = "https://github.com/rust-analyzer/rust-analyzer/pull/#{pr}"
parent.document.register :links, target
(create_anchor parent, "<code>##{pr}</code>", type: :link, target: target).convert
end
end
class CommitInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
use_dsl
named :commit
def process parent, target, attrs
hash = target
target = "https://github.com/rust-analyzer/rust-analyzer/commit/#{hash}"
parent.document.register :links, target
(create_anchor parent, "<code>#{hash[0..6]}</code>", type: :link, target: target).convert
end
end
class ReleaseInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
use_dsl
named :release
def process parent, target, attrs
date = target
target = "https://github.com/rust-analyzer/rust-analyzer/releases/#{date}"
parent.document.register :links, target
(create_anchor parent, "<code>#{date}</code>", type: :link, target: target).convert
end
end
Asciidoctor::Extensions.register do
inline_macro PrInlineMacro
inline_macro CommitInlineMacro
inline_macro ReleaseInlineMacro
end