Skip to content

Commit a26d455

Browse files
committed
Add asciidoctor extension to better format the manpage
Signed-off-by: Jean-Noël Avila <[email protected]>
1 parent 63b48cf commit a26d455

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

asciidoctor-extensions.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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? 'manpage'
19+
"#{target}(#{attrs[1]})"
20+
end
21+
end
22+
end
23+
end
24+
end
25+
26+
Asciidoctor::Extensions.register do
27+
inline_macro Git::Documentation::LinkGitProcessor, :linkgit
28+
end

makefile.locale

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ include ../../Makefile
2222

2323
XMLTO_EXTRA += --searchpath ../..
2424
ifdef USE_ASCIIDOCTOR
25-
ASCIIDOC_EXTRA += -I../..
25+
ASCIIDOC_EXTRA += -I../.. -I. -rasciidoctor-extensions
2626
else
2727
ASCIIDOC_CONF = -f ../../asciidoc.conf
2828
endif
@@ -43,12 +43,17 @@ ifndef V
4343
QUIET_ASCIIDOC = @echo ' ' ASCIIDOC $(lang) $@;
4444
endif
4545

46+
-include ../GIT-VERSION-FILE
47+
4648
$(HTML_FILTER): %.html: %.txt
47-
$(QUIET_ASCIIDOC)asciidoctor -b xhtml5 -d manpage $<
49+
$(QUIET_ASCIIDOC)asciidoctor -b xhtml5 -d manpage -d manpage -I.. -I. -rasciidoctor-extensions \
50+
-amanversion=$(GIT_VERSION) -amanmanual='Git Manual' -amansource='Git $(GIT_VERSION)' $<
4851

4952
MANPAGES=$(patsubst %.txt,%.1,$(MAN_FILTER))
5053
$(MANPAGES): %.1: %.txt
51-
$(QUIET_ASCIIDOC)asciidoctor -b manpage -d manpage -o $@ $<
54+
$(QUIET_ASCIIDOC)asciidoctor -b manpage -d manpage -o $@ \
55+
-I. -I.. -rasciidoctor-extensions \
56+
-amanmanual='Git Manual' -amansource='Git $(GIT_VERSION)' $<
5257

5358
man: $(MANPAGES)
5459
html: $(HTML_FILTER)

0 commit comments

Comments
 (0)