2 require 'asciidoctor/extensions'
6 class LinkGitProcessor < Asciidoctor::Extensions::InlineMacroProcessor
11 def process(parent, target, attrs)
12 gitscm = 'https://git-scm.com/docs/'
13 if parent.document.doctype == 'book' \
14 or parent.document.doctype == 'article'
15 "<ulink url=\"#{gitscm}#{target}\">" \
16 "#{target}(#{attrs[1]})</ulink>"
17 elsif parent.document.basebackend? 'html'
18 %(<a href="#{gitscm}#{target}">#{target}(#{attrs[1]})</a>)
19 elsif parent.document.basebackend? 'docbook'
21 "<refentrytitle>#{target}</refentrytitle>" \
22 "<manvolnum>#{attrs[1]}</manvolnum>\n" \
28 class LinkManProcessor < Asciidoctor::Extensions::InlineMacroProcessor
33 def process(parent, target, attrs)
34 if parent.document.doctype == 'book' \
35 or parent.document.doctype == 'article'
36 "<ulink url=\"#{target}.html\">#{target}(#{attrs[1]})</ulink>"
37 elsif parent.document.basebackend? 'html'
38 %(<a href="#{target}.html">#{target}(#{attrs[1]})</a>)
39 elsif parent.document.basebackend? 'docbook'
41 "<refentrytitle>#{target}</refentrytitle>" \
42 "<manvolnum>#{attrs[1]}</manvolnum>\n" \
48 class LinkStgProcessor < Asciidoctor::Extensions::InlineMacroProcessor
53 def process(parent, target, attrs)
54 if parent.document.doctype == 'book' \
55 or parent.document.doctype == 'article'
56 "<ulink url=\"stg-#{target}.html\">stg #{target}</ulink>"
57 elsif parent.document.basebackend? 'html'
58 %(<a href="stg-#{target}.html">stg #{target}</a>)
59 elsif parent.document.basebackend? 'docbook'
61 "<refentrytitle>stg-#{target}</refentrytitle>" \
62 "<manvolnum>1</manvolnum>\n" \
68 class LinkStgSubProcessor < Asciidoctor::Extensions::InlineMacroProcessor
73 def process(parent, target, attrs)
74 if parent.document.doctype == 'book' \
75 or parent.document.doctype == 'article'
76 "<ulink url=\"stg-#{target}.html\">#{target}</ulink>"
77 elsif parent.document.basebackend? 'html'
78 %(<a href="stg-#{target}.html">#{target}</a>)
79 elsif parent.document.basebackend? 'docbook'
81 "<refentrytitle>stg-#{target}</refentrytitle>" \
82 "<manvolnum>1</manvolnum>\n" \
88 class DocumentPostProcessor < Asciidoctor::Extensions::Postprocessor
89 def process document, output
90 if document.basebackend? 'docbook'
91 mansource = document.attributes['mansource']
92 manversion = document.attributes['manversion']
93 manmanual = document.attributes['manmanual']
95 "<refmiscinfo class=\"source\">#{mansource}</refmiscinfo>\n" \
96 "<refmiscinfo class=\"version\">#{manversion}</refmiscinfo>\n" \
97 "<refmiscinfo class=\"manual\">#{manmanual}</refmiscinfo>\n"
98 output = output.sub(/<\/refmeta>/, new_tags + "</refmeta>")
106 Asciidoctor::Extensions.register do
107 inline_macro StGit::Documentation::LinkGitProcessor, :linkgit
108 inline_macro StGit::Documentation::LinkManProcessor, :linkman
109 inline_macro StGit::Documentation::LinkStgProcessor, :linkstg
110 inline_macro StGit::Documentation::LinkStgSubProcessor, :linkstgsub
111 postprocessor StGit::Documentation::DocumentPostProcessor