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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Oct 11, 2014 at 23:37 UTC
773ee47c2b9c691d9758b2bea6cac10e3f0c4e12
1 file changed
+39
Documentation/extensions.rb
new
+39
@@ -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