Skip to content

Commit 773ee47

Browse files
bk2204gitster
authored andcommitted
Documentation: implement linkgit macro for Asciidoctor
AsciiDoc uses a configuration file to implement macros like linkgit, while Asciidoctor uses Ruby extensions. Implement a Ruby extension that implements the linkgit macro for Asciidoctor in the same way that asciidoc.conf does for AsciiDoc. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7d61547 commit 773ee47

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Documentation/extensions.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'asciidoctor'
2+
require 'asciidoctor/extensions'
3+
4+
module Git
5+
module Documentation
6+
class LinkGitProcessor < Asciidoctor::Extensions::InlineMacroProcessor
7+
use_dsl
8+
9+
named :chrome
10+
11+
def process(parent, target, attrs)
12+
if parent.document.basebackend? 'html'
13+
generate_html(parent, target, attrs)
14+
elsif parent.document.basebackend? 'docbook'
15+
generate_docbook(parent, target, attrs)
16+
end
17+
end
18+
19+
private
20+
21+
def generate_html(parent, target, attrs)
22+
section = attrs.has_key?(1) ? "(#{attrs[1]})" : ''
23+
prefix = parent.document.attr('git-relative-html-prefix') || ''
24+
%(<a href="#{prefix}#{target}.html">#{target}#{section}</a>\n)
25+
end
26+
27+
def generate_docbook(parent, target, attrs)
28+
%(<citerefentry>
29+
<refentrytitle>#{target}</refentrytitle><manvolnum>#{attrs[1]}</manvolnum>
30+
</citerefentry>
31+
)
32+
end
33+
end
34+
end
35+
end
36+
37+
Asciidoctor::Extensions.register do
38+
inline_macro Git::Documentation::LinkGitProcessor, :linkgit
39+
end

0 commit comments

Comments
 (0)