summaryrefslogtreecommitdiffstats
path: root/docbook/asciidoctor-macros/manarg-block
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--docbook/asciidoctor-macros/manarg-block.rb8
-rw-r--r--docbook/asciidoctor-macros/manarg-block/extension.rb45
-rw-r--r--docbook/asciidoctor-macros/manarg-block/sample.adoc19
3 files changed, 72 insertions, 0 deletions
diff --git a/docbook/asciidoctor-macros/manarg-block.rb b/docbook/asciidoctor-macros/manarg-block.rb
new file mode 100644
index 00000000..07a9bf26
--- /dev/null
+++ b/docbook/asciidoctor-macros/manarg-block.rb
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: MIT
+# Adapted from https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/man-inline-macro.rb
+
+RUBY_ENGINE == 'opal' ? (require 'manarg-block/extension') : (require_relative 'manarg-block/extension')
+
+Extensions.register do
+ block ManArgBlock
+end
diff --git a/docbook/asciidoctor-macros/manarg-block/extension.rb b/docbook/asciidoctor-macros/manarg-block/extension.rb
new file mode 100644
index 00000000..2461e723
--- /dev/null
+++ b/docbook/asciidoctor-macros/manarg-block/extension.rb
@@ -0,0 +1,45 @@
+# SPDX-License-Identifier: MIT
+require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
+
+include Asciidoctor
+
+# An inline macro that generates markup for man page arguments.
+# Adapted from https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/man-inline-macro.rb
+#
+# Usage:
+#
+# [manarg]
+# *command*
+# [ *--help* ]
+# [ *--flash-lights* ]
+#
+class ManArgBlock < Extensions::BlockProcessor
+ use_dsl
+
+ named :manarg
+ parse_content_as :simple
+
+ def process parent, reader, attrs
+ nowrap_lines = reader.readlines.map {|line|
+ if parent.document.basebackend? 'html'
+ # Apply the custom style "[.nowrap]## ... ##" to each line.
+ # This generates "<span content="nowrap"> ... </span>". Pass
+ # each '#' through for extra paranoia.
+ %([.nowrap]###{line.gsub('#', '+++#+++')}##)
+ elsif parent.document.backend == 'manpage'
+ # Replace spaces with non-breaking spaces ('&#160;'), then make
+ # bold markup unconstrained ('*' -> '**'). For now we naively
+ # assume that bolds are always constrained (that is, we only
+ # have single '*'s). We *should* be able to do this properly
+ # with a regex, but for some reason
+ # gsub(/([^*])\*([^*])/, '\1**\2')
+ # doesn't match the first asterisk in "*--extcap-interface*=<interface>"
+ %(#{line.gsub(' ', '&#160;').gsub('*', '**')})
+ else
+ line
+ end
+ }
+ # STDERR.puts(nowrap_lines)
+ create_paragraph parent, nowrap_lines, attrs
+ end
+end
diff --git a/docbook/asciidoctor-macros/manarg-block/sample.adoc b/docbook/asciidoctor-macros/manarg-block/sample.adoc
new file mode 100644
index 00000000..5b4a4019
--- /dev/null
+++ b/docbook/asciidoctor-macros/manarg-block/sample.adoc
@@ -0,0 +1,19 @@
+= androiddump(1)
+:doctype: manpage
+
+== NAME
+
+sample - Sample man page
+
+== SYNOPSIS
+
+[manarg]
+*androiddump*
+*--mandatory-argument
+[ *--optional-argument* ]
+*--complex-mandatory*=<argument>
+[ *--complex-optional*=<argument> ]
+
+== DESCRIPTION
+
+Sample man page.