Skip to content

Commit

Permalink
resolves #1922 use value of author attribute in PDF info and pdfmark …
Browse files Browse the repository at this point in the history
…if authors attribute is not set (PR #1923)
  • Loading branch information
mojavelinux committed May 5, 2021
1 parent e4e65f9 commit 73be746
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Enhancements::
* disable document outline if outline document attribute is unset (#1619)
* keep temporary artifacts (for debugging) if KEEP_ARTIFACTS env var is set
* define a dest name "toc" at the top of the default toc location
* normalize whitespace in authors content and drop lines with unresolved attribute references (#1642)
* normalize space characters in authors content and drop lines with unresolved attribute references (#1642)
* skip image block with missing image if computed alt text resolves to empty string (#1645)
* custom theme does not inherit from base theme by default; must be specified explicitly using `extends: base` (#1640)
* allow theme to confiure number of index columns using `index_columns` key (#1663)
Expand Down Expand Up @@ -157,6 +157,7 @@ Bug Fixes::
* prevent PDF from being used as logo image on title page (since it cannot work properly anyway)
* don't crash when generating TOC if section title is empty
* escape closing square bracket around alt text of missing image so it doesn't get matched as part of a link macro
* use value of author attribute in PDF info and pdfmark if authors attribute is not set (#1922)

Compliance::

Expand Down
2 changes: 2 additions & 0 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@ def build_pdf_info doc
info[:Author] = (sanitize doc.attr 'author').as_pdf
elsif doc.attr? 'authors'
info[:Author] = (sanitize doc.attr 'authors').as_pdf
elsif doc.attr? 'author' # rubocop:disable Lint/DuplicateBranch
info[:Author] = (sanitize doc.attr 'author').as_pdf
end
info[:Subject] = (sanitize doc.attr 'subject').as_pdf if doc.attr? 'subject'
info[:Keywords] = (sanitize doc.attr 'keywords').as_pdf if doc.attr? 'keywords'
Expand Down
2 changes: 2 additions & 0 deletions lib/asciidoctor/pdf/pdfmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def generate
author = sanitize doc.attr 'author'
elsif doc.attr? 'authors'
author = sanitize doc.attr 'authors'
elsif doc.attr? 'author' # rubocop:disable Lint/DuplicateBranch
author = sanitize doc.attr 'author'
end
# see https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdfmark_reference.pdf
<<~EOS
Expand Down
22 changes: 22 additions & 0 deletions spec/pdf_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@
(expect pdf.info[:Author]).to eql 'Doc Writer'
end

it 'should set Author field to value of author attribute if document has no doctitle' do
pdf = to_pdf <<~'EOS'
:author: Author Name
== Section Title
content
EOS
(expect pdf.info[:Author]).to eql 'Author Name'
end

it 'should set Author field to value of authors attribute if document has no doctitle' do
pdf = to_pdf <<~'EOS'
:authors: Author Name
== Section Title
content
EOS
(expect pdf.info[:Author]).to eql 'Author Name'
end

it 'should set Producer field to value of publisher attribute if set' do
pdf = to_pdf <<~'EOS'
= Document Title
Expand Down
28 changes: 28 additions & 0 deletions spec/pdfmark_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,34 @@
(expect contents).to end_with %(/DOCINFO pdfmark\n)
end

it 'should set Author field to value of author attribute if document has no doctitle' do
doc = Asciidoctor.load <<~'EOS', safe: :safe
:author: Author Name
== Section Title
content
EOS

contents = (subject.new doc).generate
(expect contents).to include '/Author (Author Name)'
(expect contents).to end_with %(/DOCINFO pdfmark\n)
end

it 'should set Author field to value of authors attribute if document has no doctitle' do
doc = Asciidoctor.load <<~'EOS', safe: :safe
:authors: Author Name
== Section Title
content
EOS

contents = (subject.new doc).generate
(expect contents).to include '/Author (Author Name)'
(expect contents).to end_with %(/DOCINFO pdfmark\n)
end

it 'should set date to Unix epoch in UTC if reproducible attribute is set' do
doc = Asciidoctor.load <<~'EOS', safe: :safe
= Document Title
Expand Down

0 comments on commit 73be746

Please sign in to comment.