summaryrefslogtreecommitdiff
path: root/Documentation/asciidoctor-extensions.rb
diff options
context:
space:
mode:
authorLibravatar brian m. carlson <sandals@crustytoothpaste.net>2017-01-26 00:13:44 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-01-31 12:18:18 -0800
commit55d2d812e49aece049b73682ad5980ea84e23839 (patch)
tree7ce2c800db0fc5755a773cee45b7c7f82588c5ee /Documentation/asciidoctor-extensions.rb
parentMakefile: add a knob to enable the use of Asciidoctor (diff)
downloadtgif-55d2d812e49aece049b73682ad5980ea84e23839.tar.xz
Documentation: implement linkgit macro for Asciidoctor
AsciiDoc uses a configuration file to implement macros like linkgit, while Asciidoctor uses Ruby extensions. Implement a Ruby extension that implements the linkgit macro for Asciidoctor in the same way that asciidoc.conf does for AsciiDoc. Adjust the Makefile to use it by default. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'Documentation/asciidoctor-extensions.rb')
-rw-r--r--Documentation/asciidoctor-extensions.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/Documentation/asciidoctor-extensions.rb b/Documentation/asciidoctor-extensions.rb
new file mode 100644
index 0000000000..ec83b4959e
--- /dev/null
+++ b/Documentation/asciidoctor-extensions.rb
@@ -0,0 +1,28 @@
+require 'asciidoctor'
+require 'asciidoctor/extensions'
+
+module Git
+ module Documentation
+ class LinkGitProcessor < Asciidoctor::Extensions::InlineMacroProcessor
+ use_dsl
+
+ named :chrome
+
+ def process(parent, target, attrs)
+ if parent.document.basebackend? 'html'
+ prefix = parent.document.attr('git-relative-html-prefix')
+ %(<a href="#{prefix}#{target}.html">#{target}(#{attrs[1]})</a>\n)
+ elsif parent.document.basebackend? 'docbook'
+ "<citerefentry>\n" \
+ "<refentrytitle>#{target}</refentrytitle>" \
+ "<manvolnum>#{attrs[1]}</manvolnum>\n" \
+ "</citerefentry>\n"
+ end
+ end
+ end
+ end
+end
+
+Asciidoctor::Extensions.register do
+ inline_macro Git::Documentation::LinkGitProcessor, :linkgit
+end