From: Jean-Noël Avila via GitGitGadget Date: Sun, 11 Aug 2024 15:20:09 GMT Subject: [PATCH v3 0/3] doc: introducing synopsis para Message-ID: In-Reply-To: Following several issues with the way the formatting of synopsis is done in the manpages that were recently reworked, this patch series introduces the processing of a new custom paragraph attribute 'synopsis'. Additionally, as s macro is introduce to apply the same rules freely in the text. This extension is added to asciidoc and asciidoctor and lets write the synopsis of the commands without any typeset. 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. Jean-Noël Avila (3): doc: introduce a synopsis custom paragraph attribute doc: update the guidelines to reflect the current formatting rules doc: apply synopsis simplification on git-clone and git-init Documentation/CodingGuidelines | 54 +++++++++--------- Documentation/asciidoc.conf | 21 ++++++- Documentation/asciidoctor-extensions.rb | 33 +++++++++++ Documentation/git-clone.txt | 76 ++++++++++++------------- Documentation/git-init.txt | 33 +++++------ Documentation/urls.txt | 26 ++++----- t/t0450-txt-doc-vs-help.sh | 11 ++-- 7 files changed, 150 insertions(+), 104 deletions(-) base-commit: ad57f148c6b5f8735b62238dda8f571c582e0e54 Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1766%2Fjnavila%2Fdoc_synopsis_para-v3 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1766/jnavila/doc_synopsis_para-v3 Pull-Request: https://github.com/gitgitgadget/git/pull/1766 Range-diff vs v2: 1: aba144f4ff3 ! 1: 0d7c1dd8f26 doc: introduce a synopsis custom paragraph attribute @@ Commit message 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. + Signed-off-by: Jean-Noël Avila ## Documentation/asciidoc.conf ## -@@ Documentation/asciidoc.conf: git-relative-html-prefix= +@@ + + [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}'))} + endif::backend-docbook[] + + ifdef::backend-docbook[] +@@ Documentation/asciidoc.conf: ifdef::backend-xhtml11[] + git-relative-html-prefix= [linkgit-inlinemacro] {target}{0?({0})} - endif::backend-xhtml11[] ++ ++[s-inlinemacro] ++{eval:re.sub(r'(<[-a-zA-Z0-9.]+>)', r'\1', re.sub(r'([\[ |()>]|^|\]|>)(\.?[-=a-zA-Z0-9:+,@]+\.?)',r'\1\2', '{attrlist}'))} ++ ++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'" -+endif::backend-xhtml11[] ++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 + ++ 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' @@ 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(/([\[\] |()>]|^)([-a-zA-Z0-9:+=]+)/, '\1{empty}`\2`{empty}') + .gsub(/(<[-a-zA-Z0-9.]+>)/, '__\\1__') + .gsub(']', ']{empty}') + end @@ Documentation/asciidoctor-extensions.rb: module Git Asciidoctor::Extensions.register do inline_macro Git::Documentation::LinkGitProcessor, :linkgit ++ inline_macro Git::Documentation::SynopsisMacroProcessor + block Git::Documentation::SynopsisBlock postprocessor Git::Documentation::DocumentPostProcessor end 2: b6387bef40d ! 2: 92f3121cf4e doc: update the guidelines to reflect the current formatting rules @@ Commit message ## Documentation/CodingGuidelines ## @@ Documentation/CodingGuidelines: Markup: + __ + + 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 ____ +- Unconstrained formatting for literal formatting is ++like this++ +- `--jobs` __ +- ++--sort=++____ +- ____++/.git++ +- ++remote.++____++.mirror++ +- +- 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. Synopsis Syntax 3: 2a61e0945de ! 3: 02406b91894 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: 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 ++__. + + `--no-hardlinks`:: + Force the cloning process from a repository on a local +@@ Documentation/git-clone.txt: If you want to break the dependency of a repository cloned with `--shared` on + its source repository, you can simply run `git repack -a` to copy all + objects from the source repository into a pack in the cloned repository. + +-`--reference`[`-if-able`] __:: ++s:["--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 the cloned repository. + is specified. This flag forces progress status even if the + standard error stream is not directed to a terminal. + +-++--server-option=++__