Merge branch 'jx/t5411-flake-fix'
[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
27     class DocumentPostProcessor < Asciidoctor::Extensions::Postprocessor
28       def process document, output
29         if document.basebackend? 'docbook'
30           mansource = document.attributes['mansource']
31           manversion = document.attributes['manversion']
32           manmanual = document.attributes['manmanual']
33           new_tags = "" \
34             "<refmiscinfo class=\"source\">#{mansource}</refmiscinfo>\n" \
35             "<refmiscinfo class=\"version\">#{manversion}</refmiscinfo>\n" \
36             "<refmiscinfo class=\"manual\">#{manmanual}</refmiscinfo>\n"
37           output = output.sub(/<\/refmeta>/, new_tags + "</refmeta>")
38         end
39         output
40       end
41     end
42   end
43 end
44
45 Asciidoctor::Extensions.register do
46   inline_macro Git::Documentation::LinkGitProcessor, :linkgit
47   postprocessor Git::Documentation::DocumentPostProcessor
48 end