Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed generation of document header for DocBook 5 book #58

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/docbookrx/docbook_visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,20 +418,28 @@ def visit_chapter node
end

def process_doc node
# In DocBook 5.0, title is directly inside book/article element
if (title = text_at_css node, '> title')
append_line %(= #{title})
append_blank_line
end
@level += 1
proceed node, :using_elements => true
@level -= 1
false
end

def process_info node
title = text_at_css node, '> title'
append_line %(= #{title})
# In DocBook 4.5, title is nested inside info element
if (title = text_at_css node, '> title')
append_line %(= #{title})
append_blank_line
end
authors = []
(node.css 'author').each do |author_node|
# FIXME need to detect DocBook 4.5 vs 5.0 to handle names properly
author = if (personname_node = (author_node.at_css 'personname'))
text personname_node
[(text_at_css personname_node, 'firstname'), (text_at_css personname_node, 'surname')].compact * ' '
else
[(text_at_css author_node, 'firstname'), (text_at_css author_node, 'surname')].compact * ' '
end
Expand Down
44 changes: 43 additions & 1 deletion spec/lib/docbookrx/docbookrx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'spec_helper'

describe 'Conversion' do
it 'should create a document header with title, author and attributes' do
it 'should create a document header with title, author and attributes from DocBook 4.5 content' do
input = <<-EOS
<?xml version="1.0" encoding="UTF-8"?>
<book xmlns="http://docbook.org/ns/docbook">
Expand All @@ -23,6 +23,48 @@

expected = <<-EOS.rstrip
= Document Title

Doc Writer <[email protected]>
:doctype: book
:sectnums:
:toc: left
:icons: font
:experimental:

== First Section

content
EOS

output = Docbookrx.convert input

expect(output).to eq(expected)
end

it 'should create a document header with title, author and attributes from DocBook 5 content' do
input = <<-EOS
<?xml version="1.0" encoding="UTF-8"?>
<book xmlns="http://docbook.org/ns/docbook">
<title>Document Title</title>
<info>
<author>
<personname>
<firstname>Doc</firstname>
<surname>Writer</surname>
</personname>
<email>[email protected]</email>
</author>
</info>
<section>
<title>First Section</title>
<para>content</para>
</section>
</book>
EOS

expected = <<-EOS.rstrip
= Document Title

Doc Writer <[email protected]>
:doctype: book
:sectnums:
Expand Down