From a26d455f4a4b1518c262a8de85329f01d45473bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Avila?= <jn.avila@free.fr> Date: Fri, 17 Jan 2020 19:16:39 +0100 Subject: [PATCH] Add asciidoctor extension to better format the manpage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jean-No챘l Avila <jn.avila@free.fr> --- asciidoctor-extensions.rb | 28 ++++++++++++++++++++++++++++ makefile.locale | 11 ++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 asciidoctor-extensions.rb diff --git a/asciidoctor-extensions.rb b/asciidoctor-extensions.rb new file mode 100644 index 0000000..0098be6 --- /dev/null +++ b/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) + prefix = parent.document.attr('git-relative-html-prefix') + if parent.document.doctype == 'book' + "<ulink url=\"#{prefix}#{target}.html\">" \ + "#{target}(#{attrs[1]})</ulink>" + elsif parent.document.basebackend? 'html' + %(<a href="#{prefix}#{target}.html">#{target}(#{attrs[1]})</a>) + elsif parent.document.basebackend? 'manpage' + "#{target}(#{attrs[1]})" + end + end + end + end +end + +Asciidoctor::Extensions.register do + inline_macro Git::Documentation::LinkGitProcessor, :linkgit +end diff --git a/makefile.locale b/makefile.locale index b6ac090..f678c04 100644 --- a/makefile.locale +++ b/makefile.locale @@ -22,7 +22,7 @@ include ../../Makefile XMLTO_EXTRA += --searchpath ../.. ifdef USE_ASCIIDOCTOR -ASCIIDOC_EXTRA += -I../.. +ASCIIDOC_EXTRA += -I../.. -I. -rasciidoctor-extensions else ASCIIDOC_CONF = -f ../../asciidoc.conf endif @@ -43,12 +43,17 @@ ifndef V QUIET_ASCIIDOC = @echo ' ' ASCIIDOC $(lang) $@; endif +-include ../GIT-VERSION-FILE + $(HTML_FILTER): %.html: %.txt - $(QUIET_ASCIIDOC)asciidoctor -b xhtml5 -d manpage $< + $(QUIET_ASCIIDOC)asciidoctor -b xhtml5 -d manpage -d manpage -I.. -I. -rasciidoctor-extensions \ + -amanversion=$(GIT_VERSION) -amanmanual='Git Manual' -amansource='Git $(GIT_VERSION)' $< MANPAGES=$(patsubst %.txt,%.1,$(MAN_FILTER)) $(MANPAGES): %.1: %.txt - $(QUIET_ASCIIDOC)asciidoctor -b manpage -d manpage -o $@ $< + $(QUIET_ASCIIDOC)asciidoctor -b manpage -d manpage -o $@ \ + -I. -I.. -rasciidoctor-extensions \ + -amanmanual='Git Manual' -amansource='Git $(GIT_VERSION)' $< man: $(MANPAGES) html: $(HTML_FILTER) -- GitLab