Skip to content

Commit

Permalink
resolves asciidoctor#4024 suppress missing attribute warning when pro…
Browse files Browse the repository at this point in the history
…cessing value for doctitle attribute (PR asciidoctor#4025)

suppress missing attribute warning when applying substitutions to implicit document title to assign to doctitle attribute

author should assume there's an implicit attribute entry for doctitle directly after the document title (level-0 section title)
  • Loading branch information
mojavelinux authored and ggrossetie committed Jun 12, 2021
1 parent 6f04a39 commit 7a13e92
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -22,6 +22,7 @@ Bug Fixes::
* Allow showtitle/notitle to be toggled in AsciiDoc table cell if set in parent document (#4018)
* Ensure mtime of input file honors TZ environment variable on JRuby for Windows (affects value of docdatetime attribute) (#3550)
* Honor caption attribute on blocks that support captioned title even if corresponding *-caption document attribute is not set (#4023)
* Suppress missing attribute warning when applying substitutions to implicit document title to assign to doctitle attribute (#4024)

Improvements::

Expand Down
5 changes: 4 additions & 1 deletion lib/asciidoctor/parser.rb
Expand Up @@ -144,7 +144,10 @@ def self.parse_document_header(reader, document)
l0_section_title = nil
else
document.title = l0_section_title
doc_attrs['doctitle'] = doctitle_attr_val = document.apply_header_subs l0_section_title
if (doc_attrs['doctitle'] = doctitle_attr_val = document.sub_specialchars l0_section_title).include? ATTR_REF_HEAD
# QUESTION should we defer substituting attributes until the end of the header? or should we substitute again if necessary?
doc_attrs['doctitle'] = doctitle_attr_val = document.sub_attributes doctitle_attr_val, attribute_missing: 'skip'
end
end
document.header.source_location = source_location if source_location
# default to compat-mode if document has setext doctitle
Expand Down
40 changes: 36 additions & 4 deletions test/document_test.rb
Expand Up @@ -703,16 +703,48 @@
assert_xpath '//*[@id="preamble"]//p[text()="Override"]', doc.convert, 1
end

test 'header substitutions should be applied to the value of the doctitle attribute' do
test 'should apply header substitutions to value of the doctitle attribute assigned from implicit doctitle' do
input = <<~'EOS'
= <Foo> & <Bar>
= <Foo> {plus} <Bar>
The name of the game is {doctitle}.
EOS

doc = document_from_string input
assert_equal '&lt;Foo&gt; &amp; &lt;Bar&gt;', (doc.attr 'doctitle')
assert_includes doc.blocks[0].content, '&lt;Foo&gt; &amp; &lt;Bar&gt;'
assert_equal '&lt;Foo&gt; &#43; &lt;Bar&gt;', (doc.attr 'doctitle')
assert_includes doc.blocks[0].content, '&lt;Foo&gt; &#43; &lt;Bar&gt;'
end

test 'should substitute attribute reference in implicit document title for attribute defined earlier in header' do
using_memory_logger do |logger|
input = <<~'EOS'
:project-name: ACME
= {project-name} Docs
{doctitle}
EOS
doc = document_from_string input, attributes: { 'attribute-missing' => 'warn' }
assert_empty logger
assert_equal 'ACME Docs', (doc.attr 'doctitle')
assert_equal 'ACME Docs', doc.doctitle
assert_xpath '//p[text()="ACME Docs"]', doc.convert, 1
end
end

test 'should not warn if implicit document title contains attribute reference for attribute defined later in header' do
using_memory_logger do |logger|
input = <<~'EOS'
= {project-name} Docs
:project-name: ACME
{doctitle}
EOS
doc = document_from_string input, attributes: { 'attribute-missing' => 'warn' }
assert_empty logger
assert_equal '{project-name} Docs', (doc.attr 'doctitle')
assert_equal 'ACME Docs', doc.doctitle
assert_xpath '//p[text()="{project-name} Docs"]', doc.convert, 1
end
end

test 'should recognize document title when preceded by blank lines' do
Expand Down

0 comments on commit 7a13e92

Please sign in to comment.