@@ -2,15 +2,21 @@ require 'asciidoctor/extensions'
Asciidoctor::Extensions.register do
+ doc = document
+
inline_macro :linkgit do
- process do |parent, target, attrs|
- if parent.document.doctype == 'book'
+ if doc.doctype == 'book'
+ process do |parent, target, attrs|
"<ulink url=\"#{target}.html\">" \
"#{target}(#{attrs[1]})</ulink>"
- elsif parent.document.basebackend? 'html'
- prefix = parent.document.attr('git-relative-html-prefix')
+ end
+ elsif doc.basebackend? 'html'
+ prefix = doc.attr('git-relative-html-prefix')
+ process do |parent, target, attrs|
%(<a href="#{prefix}#{target}.html">#{target}(#{attrs[1]})</a>)
- elsif parent.document.basebackend? 'docbook'
+ end
+ elsif doc.basebackend? 'docbook'
+ process do |parent, target, attrs|
"<citerefentry>\n" \
"<refentrytitle>#{target}</refentrytitle>" \
"<manvolnum>#{attrs[1]}</manvolnum>\n" \
There is no need to execute extra code every time the process block is called. In Ruby the lexical scope is shared, so we can define variables in the register block scope, and all the rest will inherit those variables. Based on the doctype and basebackend one of three blocks is selected for the inline_macro. However, the conditionals will be run only once. In the end Ruby will only run the code between `process do end`, nothing else. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> --- Documentation/asciidoctor-extensions.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)