Skip to content

Commit

Permalink
resolves asciidoctor#3602 move abstract inside info tag in DocBook ou…
Browse files Browse the repository at this point in the history
…tput
  • Loading branch information
mojavelinux committed Oct 27, 2023
1 parent fd7b62d commit e8356db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -69,6 +69,7 @@ Bug Fixes::

* Preserve paragraph breaks in normal table cell in manpage output (#4481)
* Escape spaces in include target (using inline passthrough) when generating link from include directive (#4461)
* Move abstract to info in DocBook output (#3602)

== 2.0.20 (2023-05-18) - @mojavelinux

Expand Down
20 changes: 18 additions & 2 deletions lib/asciidoctor/converter/docbook5.rb
Expand Up @@ -45,7 +45,8 @@ def convert_document node
end
root_tag_idx = result.size
id = node.id
result << (document_info_tag node) unless node.noheader
abstract = extract_abstract node
result << (document_info_tag node, abstract) unless node.noheader
if manpage
result << '<refentry>'
result << '<refmeta>'
Expand All @@ -71,6 +72,7 @@ def convert_document node
# defer adding root tag in case document ID is auto-generated on demand
result.insert root_tag_idx, %(<#{root_tag_name} xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0"#{lang_attribute}#{common_attributes id}>)
result << %(</#{root_tag_name}>)
abstract.parent.blocks.insert 0, abstract if abstract
result.join LF
end

Expand Down Expand Up @@ -365,6 +367,7 @@ def convert_paragraph node
end

def convert_preamble node
return unless node.blocks?
if node.document.doctype == 'book'
%(<preface#{common_attributes node.id, node.role, node.reftext}>
#{title_tag node, false}#{node.content}
Expand Down Expand Up @@ -663,7 +666,7 @@ def author_tag doc, author
result.join LF
end

def document_info_tag doc
def document_info_tag doc, abstract
result = ['<info>']
unless doc.notitle
if (title = doc.doctitle partition: true, use_fallback: true).subtitle?
Expand Down Expand Up @@ -717,11 +720,24 @@ def document_info_tag doc
result << docinfo_content
end
end
result << (convert_open abstract) if abstract
result << '</info>'

result.join LF
end

def extract_abstract doc
return unless doc.blocks? && (first_block = doc.blocks[0]).context != :section
if first_block.context == :open
if first_block.style == 'abstract'
(abstract = first_block).parent.blocks.delete_at 0
end
elsif first_block.context == :preamble && (first_block = first_block.blocks[0]) && first_block.style == 'abstract' && first_block.context == :open
(abstract = first_block).parent.blocks.delete_at 0
end
abstract
end

def get_root_document node
while (node = node.document).nested?
node = node.parent_document
Expand Down
13 changes: 7 additions & 6 deletions test/blocks_test.rb
Expand Up @@ -3681,8 +3681,8 @@ def names
EOS

output = convert_string input, backend: 'docbook'
assert_css 'abstract', output, 1
assert_css 'abstract > simpara', output, 2
assert_css 'info > abstract', output, 1
assert_css 'info > abstract > simpara', output, 2
end

test 'should make abstract on open block with title converted to DocBook' do
Expand All @@ -3697,9 +3697,9 @@ def names
EOS

output = convert_string input, backend: 'docbook'
assert_css 'abstract', output, 1
assert_css 'abstract > title', output, 1
assert_css 'abstract > title + simpara', output, 1
assert_css 'info > abstract', output, 1
assert_css 'info > abstract > title', output, 1
assert_css 'info > abstract > title + simpara', output, 1
end

test 'should allow abstract in document with title if doctype is book converted to DocBook' do
Expand All @@ -3712,7 +3712,8 @@ def names
EOS

output = convert_string input, backend: 'docbook'
assert_css 'abstract', output, 1
assert_css 'info > abstract', output, 1
assert_css 'preface', output, 0
end

test 'should not allow abstract as direct child of document if doctype is book converted to DocBook' do
Expand Down

0 comments on commit e8356db

Please sign in to comment.