diff options
author | Lysander Trischler <github@lyse.isobeef.org> | 2022-03-16 23:59:40 +0100 |
---|---|---|
committer | Lysander Trischler <github@lyse.isobeef.org> | 2022-03-17 00:28:22 +0100 |
commit | 18209dfd90c1fda98ceef368d240324a920e2e32 (patch) | |
tree | 33bdbf2c24d240f0f7546305c1eed1c6dcf74d41 /doc | |
parent | e06b9a73fe19523f5c486cb773049f27f697e7bf (diff) |
Make man page converter work with Asciidoctor 1.x
Diffstat (limited to 'doc')
-rw-r--r-- | doc/man.rb | 46 |
1 files changed, 42 insertions, 4 deletions
@@ -30,17 +30,55 @@ # The official documentation covers the process of creating a custom converter # excellently: https://docs.asciidoctor.org/asciidoctor/latest/convert/custom/ # -# SuccessfullyTested with Asciidoctor 2.0.12. -class ManPageConverter < (Asciidoctor::Converter.for 'manpage') - register_for 'manpage' +# Successfully tested with Asciidoctor 1.5.5 and 2.0.12. +# The following import is required for the old Asciidoctor version 1.x shipped +# in Ubuntu 18.04, which we use in our CI/CD. Asciidoctor 2.x doesn't need it, +# but it also doesn't hurt. +require 'asciidoctor/converter/manpage' + +class ManPageConverter < Asciidoctor::Converter::ManPageConverter + + def convert_inline_monospaced node + %[#{ESC_BS}fI<BOUNDARY>#{node.text}</BOUNDARY>#{ESC_BS}fP] + end + + # In Asciidoctor version 1.x the method didn't have a 'convert' prefix. + def inline_quoted node + case node.type + when :monospaced + convert_inline_monospaced node + else + # Because of this super call, we have to define the exact same method + # twice and cannot use an alias. Otherwise the original method name will + # not be found. + super + end + end + + # In Asciidoctor version 2.x the method got a 'convert' prefix. def convert_inline_quoted node case node.type when :monospaced - %[#{ESC_BS}fI<BOUNDARY>#{node.text}</BOUNDARY>#{ESC_BS}fP] + convert_inline_monospaced node else + # Because of this super call, we have to define the exact same method + # twice and cannot use an alias. Otherwise the original method name will + # not be found. super end end + +end + +if defined? Asciidoctor::Converter::Factory.register + # Registering the converter in Asciidoctor version 1.x must explicitly use + # the 'Factory'. + Asciidoctor::Converter::Factory.register ManPageConverter, ['manpage'] +else + # Registering the converter in Asciidoctor version 2.x must not use the + # 'Factory'. Once support for 1.x is dropped, this can be even simplified to + # `register_for 'manpage'` in the class definition itself. + Asciidoctor::Converter.register ManPageConverter, 'manpage' end |