Skip to content

Commit 3cb6e5e

Browse files
committed
manpages: prepare for new manpage format
This commit adds a upcoming manpage format to the AsciiDoc backend. The new format changes are: * The synopsis is now a section with a dedicated style. This "synopsis" style allows to automatically format the keywords as monospaced and <placeholders> as italic. * the backticks are now used to format synopsis-like syntax in inline elements. All the manpages are processed with this format. It may upset the formatting for older manpages, making it not consistent across a page, but this will be a mild side effect, as this was not really consistent before. Signed-off-by: Jean-Noël Avila <[email protected]>
1 parent 393c098 commit 3cb6e5e

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

script/asciidoctor-extensions.rb

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
require 'asciidoctor'
2+
require 'asciidoctor/extensions'
3+
require 'asciidoctor/converter/html5'
4+
5+
module Git
6+
module Documentation
7+
class SynopsisBlock < Asciidoctor::Extensions::BlockProcessor
8+
9+
use_dsl
10+
named :synopsis
11+
parse_content_as :simple
12+
13+
def process parent, reader, attrs
14+
outlines = reader.lines.map do |l|
15+
l.gsub(/(\.\.\.?)([^\]$.])/, '`\1`\2')
16+
.gsub(%r{([\[\] |()>]|^)([-a-zA-Z0-9:+=~@,/_^\$]+)}, '\1{empty}`\2`{empty}')
17+
.gsub(/(<([[:word:]]|[-0-9.])+>)/, '__\\1__')
18+
.gsub(']', ']{empty}')
19+
end
20+
create_block parent, :verse, outlines, attrs
21+
end
22+
end
23+
24+
# register a html5 converter that takes in charge to convert monospaced text into Git style synopsis
25+
class GitHTMLConverter < Asciidoctor::Converter::Html5Converter
26+
27+
extend Asciidoctor::Converter::Config
28+
register_for 'html5'
29+
30+
def convert_inline_quoted node
31+
if node.type == :monospaced
32+
node.text.gsub(/(\.\.\.?)([^\]$.])/, '<code>\1</code>\2')
33+
.gsub(%r{([\[\s|()>.]|^|\]|&gt;)(\.?([-a-zA-Z0-9:+=~@,/_^\$]+\.{0,2})+)}, '\1<code>\2</code>')
34+
.gsub(/(&lt;([[:word:]]|[-0-9.])+&gt;)/, '<em>\1</em>')
35+
else
36+
open, close, tag = QUOTE_TAGS[node.type]
37+
if node.id
38+
class_attr = node.role ? %( class="#{node.role}") : ''
39+
if tag
40+
%(#{open.chop} id="#{node.id}"#{class_attr}>#{node.text}#{close})
41+
else
42+
%(<span id="#{node.id}"#{class_attr}>#{open}#{node.text}#{close}</span>)
43+
end
44+
elsif node.role
45+
if tag
46+
%(#{open.chop} class="#{node.role}">#{node.text}#{close})
47+
else
48+
%(<span class="#{node.role}">#{open}#{node.text}#{close}</span>)
49+
end
50+
else
51+
%(#{open}#{node.text}#{close})
52+
end
53+
end
54+
end
55+
end
56+
end
57+
end
58+
59+
60+
61+
Asciidoctor::Extensions.register do
62+
block Git::Documentation::SynopsisBlock
63+
end

script/update-docs.rb

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
require 'yaml'
1010
require 'diffy'
1111
require_relative "version"
12+
require_relative 'asciidoctor-extensions'
1213

1314
SITE_ROOT = File.join(File.expand_path(File.dirname(__FILE__)), '../')
1415
DOCS_INDEX_FILE = "#{SITE_ROOT}external/docs/content/docs/_index.html"

0 commit comments

Comments
 (0)