Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New manpage format #1921

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/sass/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $baseurl: "{{ .Site.BaseURL }}{{ if (and (ne .Site.BaseURL "/") (ne .Site.BaseUR

code {
display: inline;
padding: 0 5px;
padding: 0 0;
}

pre {
Expand Down
3 changes: 0 additions & 3 deletions assets/sass/typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ blockquote {
}

code {
@include border-radius(3px);
display: block;
padding: 10px 15px 13px;
margin-bottom: 1em;
Expand All @@ -260,8 +259,6 @@ code {
line-height: $fixed-width-line-height;
font-variant-ligatures: none;
color: $orange;
background-color: #fff;
border: solid 1px #efeee6;
}

// Quotes
Expand Down
63 changes: 63 additions & 0 deletions script/asciidoctor-extensions.rb
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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a line of comment wouldn't hurt with these regexes. Maybe best with an example:

Suggested change
l.gsub(/(\.\.\.?)([^\]$.])/, '`\1`\2')
l.gsub(/(\.\.\.?)([^\]$.])/, '`\1`\2') # wrap ellipsis in backticks: ...something => `...`something

I think the intended use is for [...<more>]? Should we include the [ and ] in the regex?

Copy link
Contributor Author

@jnavila jnavila Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is trying to differentiate the three dots in different contexts, where they have a different meaning and require different formatting.

First there is the form <commit1>...<commit2> when describing a range of commits, where the three dots are a "keyword" understood by git and must be formatted as code.

Then there is the forms used in the grammar to express repetition, such as in "<path> ..." with optionally square brackets, such as "[<path>...]" which usually appear at the end of the command line. These three dots must not be formatted as code, but left as is.

This line matches the former case and forces the corresponding format. I'll add a comment in the same line as yours.

.gsub(%r{([\[\] |()>]|^)([-a-zA-Z0-9:+=~@,/_^\$]+)}, '\1{empty}`\2`{empty}')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I don't know what this one is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is the line that matches all the words which are not placeholders and not grammar signs, and format them as code. These words (in the general sense here) are keywords (option names, enum strings, two or three dot notation, etc).

.gsub(/(<([[:word:]]|[-0-9.])+>)/, '__\\1__')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to dig deep to find what [[:word:]] does, but it seems to be a Ruby non-POSIX bracket expression: https://docs.ruby-lang.org/en/master/Regexp.html#class-Regexp-label-POSIX+Bracket+Expressions. Personally I'm not a fan, what's the advantage over \w?

Also why are the inner brackets round brackets?

I just wonder if we can simplify to:

Suggested change
.gsub(/(<([[:word:]]|[-0-9.])+>)/, '__\\1__')
.gsub(/(<[^>]+>)/, '__\\1__')

And one more question, why the double backslash in the replacement string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The '\w` is for ascii, but here, we are going to process internationalized texts (because placeholders are translated), and this processing requires the special form with double brackets. I'm not an expert in Ruby regexes; this is the form I have found to work well with the translations.

As for the using a more generic regex (expecting everything between brackets to be the placeholder's name), the placeholder's names are not supposed to contain spaces, which is perfect when we have to match something like:

 $ git foo < in-file > out-file

.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|()>.]|^|\]|&gt;)(\.?([-a-zA-Z0-9:+=~@,/_^\$]+\.{0,2})+)}, '\1<code>\2</code>')
.gsub(/(&lt;([[:word:]]|[-0-9.])+&gt;)/, '<em>\1</em>')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we more or less need to repeat the regexes here?

Copy link
Contributor Author

@jnavila jnavila Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's unfortunate, but the two regex are very alike, except that this one processes the text after some pre-processing steps, and the transformations need to be in final result form (with tags and escaped characters).

I evaluated the opportunity for factorization, but it makes the code more messy than it is already.

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
1 change: 1 addition & 0 deletions script/update-docs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading