From 3cb6e5edc959c464ddf983bbfa7314ee298caf8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Avila?= Date: Sun, 17 Nov 2024 22:24:18 +0100 Subject: [PATCH] manpages: prepare for new manpage format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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 --- script/asciidoctor-extensions.rb | 63 ++++++++++++++++++++++++++++++++ script/update-docs.rb | 1 + 2 files changed, 64 insertions(+) create mode 100644 script/asciidoctor-extensions.rb diff --git a/script/asciidoctor-extensions.rb b/script/asciidoctor-extensions.rb new file mode 100644 index 0000000000..48cad5d2d2 --- /dev/null +++ b/script/asciidoctor-extensions.rb @@ -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(/(\.\.\.?)([^\]$.])/, '\1\2') + .gsub(%r{([\[\s|()>.]|^|\]|>)(\.?([-a-zA-Z0-9:+=~@,/_^\$]+\.{0,2})+)}, '\1\2') + .gsub(/(<([[:word:]]|[-0-9.])+>)/, '\1') + 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 + %(#{open}#{node.text}#{close}) + end + elsif node.role + if tag + %(#{open.chop} class="#{node.role}">#{node.text}#{close}) + else + %(#{open}#{node.text}#{close}) + end + else + %(#{open}#{node.text}#{close}) + end + end + end + end + end +end + + + +Asciidoctor::Extensions.register do + block Git::Documentation::SynopsisBlock +end diff --git a/script/update-docs.rb b/script/update-docs.rb index 07c168fd1a..28223891ce 100644 --- a/script/update-docs.rb +++ b/script/update-docs.rb @@ -9,6 +9,7 @@ require 'yaml' require 'diffy' require_relative "version" +require_relative 'asciidoctor-extensions' SITE_ROOT = File.join(File.expand_path(File.dirname(__FILE__)), '../') DOCS_INDEX_FILE = "#{SITE_ROOT}external/docs/content/docs/_index.html"