diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2023-05-06 23:59:23 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-06 23:59:23 -0600 |
| commit | 94c53a11d6ded695dafaef1ce398842a32bbff09 (patch) | |
| tree | 6b0fbb4486ccd9f005d7a79b1a8bd7d2ea37d540 | |
| parent | c9c8373b44e2d268566f988dc7a956cd1943680f (diff) | |
resolves #4448 apply reftext substitutions to value of mantitle attribute in DocBook output (PR #4449)
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/converter/docbook5.rb | 2 | ||||
| -rw-r--r-- | lib/asciidoctor/converter/manpage.rb | 2 | ||||
| -rw-r--r-- | test/document_test.rb | 20 | ||||
| -rw-r--r-- | test/manpage_test.rb | 20 |
5 files changed, 42 insertions, 3 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index c126bfd8..b7d71f85 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -81,6 +81,7 @@ Bug Fixes:: * Implicitly attach nested list that starts with block attribute lines to dlist entry (#4268) * Don't swallow square brackets when processing escaped URL macro * Treat `uri:classloader:` as an absolute path prefix when running on JRuby (#3929) + * Apply reftext substitutions to value of `mantitle` attribute in DocBook output (#4448) == 2.0.18 (2022-10-15) - @mojavelinux diff --git a/lib/asciidoctor/converter/docbook5.rb b/lib/asciidoctor/converter/docbook5.rb index 4ae9ef10..13819e51 100644 --- a/lib/asciidoctor/converter/docbook5.rb +++ b/lib/asciidoctor/converter/docbook5.rb @@ -706,7 +706,7 @@ class Converter::DocBook5Converter < Converter::Base if doc.doctype == 'manpage' result << '<refmeta>' - result << %(<refentrytitle>#{doc.attr 'mantitle'}</refentrytitle>) if doc.attr? 'mantitle' + result << %(<refentrytitle>#{doc.apply_reftext_subs doc.attr 'mantitle'}</refentrytitle>) if doc.attr? 'mantitle' result << %(<manvolnum>#{doc.attr 'manvolnum'}</manvolnum>) if doc.attr? 'manvolnum' result << %(<refmiscinfo class="source">#{doc.attr 'mansource', ' '}</refmiscinfo>) result << %(<refmiscinfo class="manual">#{doc.attr 'manmanual', ' '}</refmiscinfo>) diff --git a/lib/asciidoctor/converter/manpage.rb b/lib/asciidoctor/converter/manpage.rb index ee0f9755..0a2f6a44 100644 --- a/lib/asciidoctor/converter/manpage.rb +++ b/lib/asciidoctor/converter/manpage.rb @@ -40,7 +40,7 @@ class Converter::ManPageConverter < Converter::Base unless node.attr? 'mantitle' raise 'asciidoctor: ERROR: doctype must be set to manpage when using manpage backend' end - mantitle = node.attr 'mantitle' + mantitle = (node.attr 'mantitle').gsub InvalidSectionIdCharsRx, '' manvolnum = node.attr 'manvolnum', '1' manname = node.attr 'manname', mantitle manmanual = node.attr 'manmanual' diff --git a/test/document_test.rb b/test/document_test.rb index 52f3316c..b29408e7 100644 --- a/test/document_test.rb +++ b/test/document_test.rb @@ -1811,6 +1811,26 @@ context 'Document' do assert_xpath %(/xmlns:refentry/xmlns:refmeta/xmlns:refmiscinfo[@class="manual"][text()="#{decode_char 160}"]), result, 1 end + test 'should apply replacements substitution to value of mantitle attribute used in DocBook output' do + input = <<~'EOS' + = foo\--bar(1) + Author Name + :doctype: manpage + :man manual: Foo Bar Manual + :man source: Foo Bar 1.0 + + == NAME + + foo--bar - puts the foo in your bar + EOS + + doc = Asciidoctor.load input, backend: :docbook, standalone: true + assert_equal 'foo\\--bar', (doc.attr 'mantitle') + result = doc.convert + assert_xpath '/xmlns:refentry/xmlns:info/xmlns:title[text()="foo--bar(1)"]', result, 1 + assert_xpath '/xmlns:refentry/xmlns:refmeta/xmlns:refentrytitle[text()="foo--bar"]', result, 1 + end + test 'should be able to set doctype to book when converting to DocBook' do input = <<~'EOS' = Title diff --git a/test/manpage_test.rb b/test/manpage_test.rb index 758b44de..10b042fa 100644 --- a/test/manpage_test.rb +++ b/test/manpage_test.rb @@ -47,6 +47,24 @@ context 'Manpage' do assert_includes output.lines, %(command, alt_command \\- does stuff\n) end + test 'should replace invalid characters in mantitle in info comment' do + input = <<~'EOS' + = foo\--<bar> (1) + Author Name + :doctype: manpage + :man manual: Foo Bar Manual + :man source: Foo Bar 1.0 + + == NAME + + foo-bar - puts the foo in your bar + EOS + + doc = Asciidoctor.load input, backend: :manpage, standalone: true + output = doc.convert + assert_includes output, %(Title: foo--bar\n) + end + test 'should substitute attributes in manname and manpurpose in NAME section' do input = <<~'EOS' = {cmdname} (1) @@ -130,7 +148,7 @@ context 'Manpage' do assert_equal '.1', doc.attr('outfilesuffix') output = doc.convert refute_empty logger.messages - assert_includes output, 'Title: cmd' + assert_includes output, %(Title: cmd\n) assert output.end_with?('garbage in') end end |
