Debian Codegraph @

docs/man/asciidoctor-extensions/manpage-extension.rb

raw symbols SCIP
1 require 'asciidoctor'
2 require 'asciidoctor/extensions'
3 require 'asciidoctor/converter/manpage'
4
5 module GitLFS
6 module Documentation
7 class GitLFSManPageConverter < Asciidoctor::Converter::ManPageConverter
8
9 extend Asciidoctor::Converter::Config
10 register_for 'manpage'
11
12 def convert_listing node
13 result = super
14 if node.role == 'synopsis'
15 # Remove any indentation from literal blocks in our "Synopsis"
16 # sections, specifically any opening ".RS <n>" and closing ".RE"
17 # macros.
18 #
19 # At present, Asciidoctor's manpage converter precedes these macros
20 # with ".if n" conditional requests so that the indentation is
21 # only added when in "n" (i.e., "nroff") mode, which by default
22 # is the case when the output device is a terminal.
23 #
24 # So as to be somewhat forgiving of potential future changes to
25 # Asciidoctor's manpage converter, we allow for the conditionals
26 # to be absent and for any indentation inset value (at present,
27 # Asciidoctor uses four spaces).
28 #
29 # References:
30 # https://www.gnu.org/software/groff/manual/groff.html#Indented-regions-in-ms
31 # https://www.gnu.org/software/groff/manual/groff.html#troff-and-nroff-Modes
32 # https://github.com/asciidoctor/asciidoctor/blob/fc0d033577d30adbffba73ce06709292fc2cf3ce/lib/asciidoctor/converter/manpage.rb#L253-L260
33
34 indent_re = /\A(?:\.if n )?(?:\.RS \d+|\.RE)\z/
35 result = result.split(Asciidoctor::LF)
36 .map {|l| l.sub(indent_re, '')}.reject {|l| l.empty?}
37 .join(Asciidoctor::LF)
38 end
39 result
40 end
41 end
42 end
43 end