Skip to content

Commit

Permalink
resolves asciidoctor#4024 suppress missing attribute warning when sub…
Browse files Browse the repository at this point in the history
…stituting value for doctitle attribute

suppress missing attribute warning when applying substitutions to implicit document title to assign to doctitle attribute
  • Loading branch information
mojavelinux committed Apr 17, 2021
1 parent b6d9c9a commit f729244
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -18,6 +18,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
Bug Fixes::

* Ensure mtime of input file honors TZ environment variable on JRuby for Windows (affects value of docdatetime attribute) (#3550)
* Suppress missing attribute warning when applying substitutions to implicit document title to assign to doctitle attribute (#4024)

Improvements::

Expand Down
4 changes: 3 additions & 1 deletion lib/asciidoctor/parser.rb
Expand Up @@ -144,7 +144,9 @@ 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
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 @@ -691,16 +691,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 f729244

Please sign in to comment.