-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <jn.avila@free.fr>
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'asciidoctor' | ||
require 'asciidoctor/extensions' | ||
require 'asciidoctor/converter/html5' | ||
|
||
module Git | ||
module Documentation | ||
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(/(\.\.\.?)([^\]$.])/, '`\1`\2') | ||
.gsub(%r{([\[\] |()>]|^)([-a-zA-Z0-9:+=~@,/_^\$]+)}, '\1{empty}`\2`{empty}') | ||
.gsub(/(<([[:word:]]|[-0-9.])+>)/, '__\\1__') | ||
.gsub(']', ']{empty}') | ||
end | ||
create_block parent, :verse, outlines, attrs | ||
end | ||
end | ||
|
||
# register a html5 converter that takes in charge to convert monospaced text into Git style synopsis | ||
class GitHTMLConverter < Asciidoctor::Converter::Html5Converter | ||
|
||
extend Asciidoctor::Converter::Config | ||
register_for 'html5' | ||
|
||
def convert_inline_quoted node | ||
if node.type == :monospaced | ||
node.text.gsub(/(\.\.\.?)([^\]$.])/, '<code>\1</code>\2') | ||
.gsub(%r{([\[\s|()>.]|^|\]|>)(\.?([-a-zA-Z0-9:+=~@,/_^\$]+\.{0,2})+)}, '\1<code>\2</code>') | ||
.gsub(/(<([[:word:]]|[-0-9.])+>)/, '<em>\1</em>') | ||
else | ||
open, close, tag = QUOTE_TAGS[node.type] | ||
if node.id | ||
class_attr = node.role ? %( class="#{node.role}") : '' | ||
if tag | ||
%(#{open.chop} id="#{node.id}"#{class_attr}>#{node.text}#{close}) | ||
else | ||
%(<span id="#{node.id}"#{class_attr}>#{open}#{node.text}#{close}</span>) | ||
end | ||
elsif node.role | ||
if tag | ||
%(#{open.chop} class="#{node.role}">#{node.text}#{close}) | ||
else | ||
%(<span class="#{node.role}">#{open}#{node.text}#{close}</span>) | ||
end | ||
else | ||
%(#{open}#{node.text}#{close}) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
||
|
||
Asciidoctor::Extensions.register do | ||
block Git::Documentation::SynopsisBlock | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters