From: Jean-Noël Avila via GitGitGadget Date: Thu, 05 Sep 2024 21:52:03 GMT Subject: [PATCH v4 0/3] doc: introducing synopsis para Message-ID: In-Reply-To: In the continuation of the simplification of manpage editing, the synopsis processing that was developed for synopsis paragraph style is also applied to all inline backquoted texts. Refining the magic regexp took more time than expected, but this one should really enhance writers'experience. I had to fight a bit more with asciidoctor, due to discrepancies between version 2.0 on my laptop and the 1.5.6 used by Github actions. The git-init and git-clone manpages are converted to this new system. Changes since V1: * switch to sed for asciidoc filter and refine the regex for support under macOS Changes since V2: * introduce the s macro to freely apply synopsis styling wherever needed, without formatting hassle. Changes since V3: * replace s macro by direct processing of literal text at the level of output processors. Jean-Noël Avila (3): doc: introduce a synopsis typesetting doc: update the guidelines to reflect the current formatting rules doc: apply synopsis simplification on git-clone and git-init Documentation/CodingGuidelines | 58 +++++++++-------- Documentation/asciidoc.conf | 20 ++++++ Documentation/asciidoctor-extensions.rb | 87 +++++++++++++++++++++++++ Documentation/git-clone.txt | 78 +++++++++++----------- Documentation/git-init.txt | 35 +++++----- Documentation/urls.txt | 26 ++++---- ci/install-dependencies.sh | 1 + t/t0450-txt-doc-vs-help.sh | 11 ++-- 8 files changed, 209 insertions(+), 107 deletions(-) base-commit: 2e7b89e038c0c888acf61f1b4ee5a43d4dd5e94c Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1766%2Fjnavila%2Fdoc_synopsis_para-v4 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1766/jnavila/doc_synopsis_para-v4 Pull-Request: https://github.com/gitgitgadget/git/pull/1766 Range-diff vs v3: 1: 0d7c1dd8f26 ! 1: c09968d7ccb doc: introduce a synopsis custom paragraph attribute @@ Metadata Author: Jean-Noël Avila ## Commit message ## - doc: introduce a synopsis custom paragraph attribute + doc: introduce a synopsis typesetting In order to follow the common manpage usage, the synopsis of the commands needs to be heavily typeset. A first try was performed with @@ Commit message 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. - - additionally, a 's' macro ('s' standing for synopsis) is introduced to - allow writers to freely apply automatic styling whereever required. + created and the processor for backticked text are modified. The + backends of asciidoc and asciidoctor take in charge to correctly add + the required typesetting. Signed-off-by: Jean-Noël Avila ## Documentation/asciidoc.conf ## -@@ - - [macros] - (?su)[\\]?(?Plinkgit):(?P\S*?)\[(?P.*?)\]= -- -+(?su)[\\]?(?Ps):(?P\S*?)\["(?P.*?)"\]= - [attributes] - asterisk=* - plus=+ @@ Documentation/asciidoc.conf: ifdef::backend-docbook[] {0#} {0#{target}{0}} {0#} + -+[s-inlinemacro] -+{eval:re.sub(r'(<[-a-zA-Z0-9.]+>)', r'\1', re.sub(r'([\[ |()>]|^|\]|>)(\.?[-a-zA-Z0-9:+=~@,\/]+\.?)',r'\1\2', '{attrlist}'))} ++[literal-inlinemacro] ++{eval:re.sub(r'(<[-a-zA-Z0-9.]+>)', r'\1', re.sub(r'([\[\s|()>]|^|\]|>)(\.?([-a-zA-Z0-9:+=~@,\/_^\$]+\.?)+)',r'\1\2', re.sub(r'(\.\.\.?)([^\]$.])', r'\1\2', macros.passthroughs[int(attrs['passtext'][1:-1])] if attrs['passtext'][1:-1].isnumeric() else attrs['passtext'][1:-1])))} ++ endif::backend-docbook[] ifdef::backend-docbook[] @@ Documentation/asciidoc.conf: ifdef::backend-xhtml11[] [linkgit-inlinemacro] {target}{0?({0})} + -+[s-inlinemacro] -+{eval:re.sub(r'(<[-a-zA-Z0-9.]+>)', r'\1', re.sub(r'([\[ |()>]|^|\]|>)(\.?[-=a-zA-Z0-9:+,@]+\.?)',r'\1\2', '{attrlist}'))} ++[literal-inlinemacro] ++{eval:re.sub(r'(<[-a-zA-Z0-9.]+>)', r'\1', re.sub(r'([\[\s|()>]|^|\]|>)(\.?([-a-zA-Z0-9:+=~@,\/_^\$]+\.?)+)',r'\1\2', re.sub(r'(\.\.\.?)([^\]$.])', r'\1\2', macros.passthroughs[int(attrs['passtext'][1:-1])] if attrs['passtext'][1:-1].isnumeric() else attrs['passtext'][1:-1])))} + +endif::backend-xhtml11[] + +ifdef::backend-docbook[] +ifdef::doctype-manpage[] +[paradef-default] -+synopsis-style=template="verseparagraph",filter="sed -E 's!([\[ |()>]|^|\])(\.?[-=a-zA-Z0-9:+@]+\.?+)!\\1\\2!g;s!<[-a-zA-Z0-9.]+>!\\0!g'" ++synopsis-style=template="verseparagraph",filter="sed -E 's!([\[ |()>]|^|\])(\.?[-=a-zA-Z0-9:+@,\/_^\$]+\.?+)!\\1\\2!g;s!<[-a-zA-Z0-9.]+>!\\0!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\\2!g;s!<[-a-zA-Z0-9.]+>!\\0!g'" ++synopsis-style=template="verseparagraph",filter="sed -E 's!([\[ |()>]|^|\])(\.?[-=a-zA-Z0-9:+@,\/_^\$]+\.?)!\\1\\2!g;s!<[-a-zA-Z0-9.]+>!\\0!g'" endif::backend-xhtml11[] ## Documentation/asciidoctor-extensions.rb ## -@@ Documentation/asciidoctor-extensions.rb: module Git - end - end +@@ + require 'asciidoctor' + require 'asciidoctor/extensions' ++require 'asciidoctor/converter/docbook5' ++require 'asciidoctor/converter/html5' -+ class SynopsisMacroProcessor < Asciidoctor::Extensions::InlineMacroProcessor -+ use_dsl -+ -+ named :s -+ match(/s:\["(.+?)"\]/) -+ -+ def process(parent, target, attrs) -+ l = target.gsub(/([\[\] |()]|^|>)(\.?[-a-zA-Z0-9:+=~@,\/]+\.?)/, '\1{empty}`\2`{empty}') -+ .gsub(/(<[-a-zA-Z0-9.]+>)/, '__\\1__') -+ .gsub(']', ']{empty}') -+ -+ create_inline parent, :quoted, l, attributes: { 'subs' => :normal } -+ end -+ end -+ - class DocumentPostProcessor < Asciidoctor::Extensions::Postprocessor - def process document, output - if document.basebackend? 'docbook' + module Git + module Documentation @@ Documentation/asciidoctor-extensions.rb: module Git output end @@ Documentation/asciidoctor-extensions.rb: module Git + + def process parent, reader, attrs + outlines = reader.lines.map do |l| -+ l.gsub(/([\[\] |()>]|^)([-a-zA-Z0-9:+=]+)/, '\1{empty}`\2`{empty}') ++ l.gsub(/(\.\.\.?)([^\]$.])/, '`\1`\2') ++ .gsub(%r{([\[\] |()>]|^)([-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 ++ ++ class GitDBConverter < Asciidoctor::Converter::DocBook5Converter ++ ++ extend Asciidoctor::Converter::Config ++ register_for 'docbook5' ++ ++ def convert_inline_quoted node ++ if (type = node.type) == :asciimath ++ # NOTE fop requires jeuclid to process mathml markup ++ asciimath_available? ? %(#{(::AsciiMath.parse node.text).to_mathml 'mml:', 'xmlns:mml' => 'http://www.w3.org/1998/Math/MathML'}) : %() ++ elsif type == :latexmath ++ # unhandled math; pass source to alt and required mathphrase element; dblatex will process alt as LaTeX math ++ %() ++ elsif type == :monospaced ++ node.text.gsub(/(\.\.\.?)([^\]$.])/, '\1\2') ++ .gsub(%r{([\[\s|()>.]|^|\]|>)(\.?([-a-zA-Z0-9:+=~@,/_^\$]+\.{0,2})+)}, '\1\2') ++ .gsub(/(<[-a-zA-Z0-9.]+>)/, '\1') ++ else ++ open, close, supports_phrase = QUOTE_TAGS[type] ++ text = node.text ++ if node.role ++ if supports_phrase ++ quoted_text = %(#{open}#{text}#{close}) ++ else ++ quoted_text = %(#{open.chop} role="#{node.role}">#{text}#{close}) ++ end ++ else ++ quoted_text = %(#{open}#{text}#{close}) ++ end ++ node.id ? %(#{quoted_text}) : quoted_text ++ end ++ 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(/(<[-a-zA-Z0-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 inline_macro Git::Documentation::LinkGitProcessor, :linkgit -+ inline_macro Git::Documentation::SynopsisMacroProcessor + block Git::Documentation::SynopsisBlock postprocessor Git::Documentation::DocumentPostProcessor end + ## ci/install-dependencies.sh ## +@@ ci/install-dependencies.sh: Documentation) + + test -n "$ALREADY_HAVE_ASCIIDOCTOR" || + sudo gem install --version 1.5.8 asciidoctor ++ sudo gem install concurrent-ruby + ;; + esac + + ## t/t0450-txt-doc-vs-help.sh ## @@ t/t0450-txt-doc-vs-help.sh: txt_to_synopsis () { fi && 2: 92f3121cf4e ! 2: c48649ccd63 doc: update the guidelines to reflect the current formatting rules @@ Commit message ## Documentation/CodingGuidelines ## @@ Documentation/CodingGuidelines: Markup: + __ + __ + +- A placeholder is not enclosed in backticks, as it is not a literal. +- + When needed, use a distinctive identifier for placeholders, usually + made of a qualification and a type: + __ __ - When literal and placeholders are mixed, each markup is applied for +- When literal and placeholders are mixed, each markup is applied for - each sub-entity. If they are stuck, a special markup, called - unconstrained formatting is required. - Unconstrained formating for placeholders is ____ @@ Documentation/CodingGuidelines: Markup: - ++--sort=++____ - ____++/.git++ - ++remote.++____++.mirror++ -- ++ Git's Asciidoc processor has been tailored to treat backticked text ++ as complex synopsis. When literal and placeholders are mixed, you can ++ use the backtick notation which will take care of correctly typesetting ++ the content. ++ `--jobs ` ++ `--sort=` ++ `/.git` ++ `remote..mirror` ++ `ssh://[@][:]/` + - caveat: ++ unconstrained format is not verbatim and may expand - content. Use Asciidoc escapes inside them. -+ each sub-entity. If the formatting is becoming too hairy, you can use the -+ s:["foo"] formatting macro and let it format the groups for you. -+ `--jobs` __ or s:["--jobs "] -+ s:["--sort= -+ s:["/.git"] -+ s:["remote..mirror"] -+ s:["ssh://[@][:]/"] -+ -+Note that the double-quotes are required by the macro. ++As a side effect, backquoted placeholders are correctly typeset, but ++this style is not recommended. Synopsis Syntax 3: 02406b91894 ! 3: 719188da711 doc: apply synopsis simplification on git-clone and git-init @@ Documentation/git-clone.txt: git-clone - Clone a repository into a new directory DESCRIPTION ----------- +@@ Documentation/git-clone.txt: OPTIONS + to save space when possible. + + + If the repository is specified as a local path (e.g., `/path/to/repo`), +-this is the default, and --local is essentially a no-op. If the ++this is the default, and `--local` is essentially a no-op. If the + repository is specified as a URL, then this flag is ignored (and we + never use the local optimizations). Specifying `--no-local` will + override the default when `/path/to/repo` is given, using the regular @@ Documentation/git-clone.txt: prevent the unintentional copying of files by dereferencing the symbolic links. + *NOTE*: this operation can race with concurrent modification to the -source repository, similar to running `cp -r src dst` while modifying -`src`. -+source repository, similar to running s:["cp -r "] while modifying ++source repository, similar to running `cp -r ` while modifying +__. `--no-hardlinks`:: @@ Documentation/git-clone.txt: If you want to break the dependency of a repository objects from the source repository into a pack in the cloned repository. -`--reference`[`-if-able`] __:: -+s:["--reference[-if-able] "]:: ++`--reference[-if-able] `:: If the reference __ is on the local machine, automatically setup `.git/objects/info/alternates` to obtain objects from the reference __. Using @@ Documentation/git-clone.txt: objects from the source repository into a pack in t standard error stream is not directed to a terminal. -++--server-option=++__