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

Draft
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Draft
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
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')
.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|()>.]|^|\]|&gt;)(\.?([-a-zA-Z0-9:+=~@,/_^\$]+\.{0,2})+)}, '\1<code>\2</code>')
.gsub(/(&lt;([[:word:]]|[-0-9.])+&gt;)/, '<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
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