asciidoctor-extensions.rb: handle "book" doctype in linkgit
[git/git.git] / Documentation / asciidoctor-extensions.rb
CommitLineData
55d2d812 1require 'asciidoctor'
2require 'asciidoctor/extensions'
3
4module Git
5 module Documentation
6 class LinkGitProcessor < Asciidoctor::Extensions::InlineMacroProcessor
7 use_dsl
8
9 named :chrome
10
11 def process(parent, target, attrs)
dba37341
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'
185f9a0e 17 %(<a href="#{prefix}#{target}.html">#{target}(#{attrs[1]})</a>)
55d2d812 18 elsif parent.document.basebackend? 'docbook'
19 "<citerefentry>\n" \
20 "<refentrytitle>#{target}</refentrytitle>" \
21 "<manvolnum>#{attrs[1]}</manvolnum>\n" \
185f9a0e 22 "</citerefentry>"
55d2d812 23 end
24 end
25 end
26 end
27end
28
29Asciidoctor::Extensions.register do
30 inline_macro Git::Documentation::LinkGitProcessor, :linkgit
31end