asciidoctor-extensions.rb: handle "book" doctype in linkgit
[git/git.git] / Documentation / asciidoctor-extensions.rb
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 prefix = parent.document.attr('git-relative-html-prefix')
13 if parent.document.doctype == 'book'
14 "<ulink url=\"#{prefix}#{target}.html\">" \
15 "#{target}(#{attrs[1]})</ulink>"
16 elsif parent.document.basebackend? 'html'
17 %(<a href="#{prefix}#{target}.html">#{target}(#{attrs[1]})</a>)
18 elsif parent.document.basebackend? 'docbook'
19 "<citerefentry>\n" \
20 "<refentrytitle>#{target}</refentrytitle>" \
21 "<manvolnum>#{attrs[1]}</manvolnum>\n" \
22 "</citerefentry>"
23 end
24 end
25 end
26 end
27 end
28
29 Asciidoctor::Extensions.register do
30 inline_macro Git::Documentation::LinkGitProcessor, :linkgit
31 end