Skip to content

Commit

Permalink
doc: introduce a synopsis custom paragraph attribute
Browse files Browse the repository at this point in the history
In order to follow the common manpage usage, the synopsis of the
commands needs to be heavily typeset. A first try was performed with
using native markup, but it turned out to make the document source
almost unreadable, difficult to write and prone to mistakes with
unwanted Asciidoc's role attributes.

In order to both simplify the writer's task and obtain a consistant
typesetting in the synopsis, a custom 'synopsis' paragraph type is
created and the backends of asciidoc and asciidoctor take in charge to
correctly add the required typesetting.

Signed-off-by: Jean-Noël Avila <[email protected]>
  • Loading branch information
jnavila committed Jul 24, 2024
1 parent ad57f14 commit 5477704
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
12 changes: 12 additions & 0 deletions Documentation/asciidoc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,15 @@ git-relative-html-prefix=
[linkgit-inlinemacro]
<a href="{git-relative-html-prefix}{target}.html">{target}{0?({0})}</a>
endif::backend-xhtml11[]

ifdef::backend-docbook[]
ifdef::doctype-manpage[]
[paradef-default]
synopsis-style=template="verseparagraph",filter="sed -E 's!([\[ |()>]|^|\])([-=a-zA-Z0-9:+.]+)!\\1<literal>\\2</literal>!g;s!&lt;[-a-zA-Z0-9.]+&gt;!<emphasis>\\0</emphasis>!g'"
endif::doctype-manpage[]
endif::backend-docbook[]

ifdef::backend-xhtml11[]
[paradef-default]
synopsis-style=template="verseparagraph",filter="sed -E 's!([\[ |()>]|^|\])([-=a-zA-Z0-9:+.]+)!\\1<code>\\2</code>!g;s!&lt;[-a-zA-Z0-9.]+&gt;!<em>\\0</em>!g'"
endif::backend-xhtml11[]
17 changes: 17 additions & 0 deletions Documentation/asciidoctor-extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,27 @@ def process document, output
output
end
end

class SynopsisBlock < Asciidoctor::Extensions::BlockProcessor

use_dsl
named :synopsis
parse_content_as :simple

def process parent, reader, attrs
outlines = reader.lines.map do |l|
l.gsub(/([\[\] |()>]|^)([-a-zA-Z0-9:+=.]+)/, '\\1{empty}`\\2`{empty}')
.gsub(/(<[-a-zA-Z0-9.]+>)/, '__\\1__')
.gsub(']', ']{empty}')
end
create_block parent, :verse, outlines, attrs
end
end
end
end

Asciidoctor::Extensions.register do
inline_macro Git::Documentation::LinkGitProcessor, :linkgit
block Git::Documentation::SynopsisBlock
postprocessor Git::Documentation::DocumentPostProcessor
end
19 changes: 8 additions & 11 deletions t/t0450-txt-doc-vs-help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,14 @@ txt_to_synopsis () {
fi &&
b2t="$(builtin_to_txt "$builtin")" &&
sed -n \
-e '/^\[verse\]$/,/^$/ {
/^$/d;
/^\[verse\]$/d;
s/_//g;
s/++//g;
s/`//g;
s/{litdd}/--/g;
s/'\''\(git[ a-z-]*\)'\''/\1/g;
p;
}' \
-E '/^\[(verse|synopsis)\]$/,/^$/ {
/^$/d;
/^\[(verse|synopsis)\]$/d;
s/\{litdd\}/--/g;
s/'\''(git[ a-z-]*)'\''/\1/g;
p;
}' \
<"$b2t" >"$out" &&
echo "$out"
}
Expand Down

0 comments on commit 5477704

Please sign in to comment.