1 # SPDX-License-Identifier: MIT
2 require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
6 # An inline macro that generates markup for man page arguments.
7 # Adapted from https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/man-inline-macro.rb
14 # [ *--flash-lights* ]
16 class ManArgBlock < Extensions::BlockProcessor
20 parse_content_as :simple
22 def process parent, reader, attrs
23 nowrap_lines = reader.readlines.map {|line|
24 if parent.document.basebackend? 'html'
25 # Apply the custom style "[.nowrap]## ... ##" to each line.
26 # This generates "<span content="nowrap"> ... </span>". Pass
27 # each '#' through for extra paranoia.
28 %([.nowrap]###{line.gsub('#', '+++#+++')}##)
29 elsif parent.document.backend == 'manpage'
30 # Replace spaces with non-breaking spaces (' '), then make
31 # bold markup unconstrained ('*' -> '**'). For now we naively
32 # assume that bolds are always constrained (that is, we only
33 # have single '*'s). We *should* be able to do this properly
34 # with a regex, but for some reason
35 # gsub(/([^*])\*([^*])/, '\1**\2')
36 # doesn't match the first asterisk in "*--extcap-interface*=<interface>"
37 %(#{line.gsub(' ', ' ').gsub('*', '**')})
42 # STDERR.puts(nowrap_lines)
43 create_paragraph parent, nowrap_lines, attrs