diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2021-10-07 02:51:06 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-07 02:51:06 -0600 |
| commit | 79424ceca876ae741716b64bd8bda5d514b0de57 (patch) | |
| tree | 387bcc9e5aa8f6ac9d836ebd797fcf0394be54e6 | |
| parent | 0bbc3ef717620180fc0f8b1a708cef6147a3a2e2 (diff) | |
resolves #4151 don't promote level-0 special section at start of document to document title (PR #4152)
| -rw-r--r-- | CHANGELOG.adoc | 4 | ||||
| -rw-r--r-- | lib/asciidoctor/parser.rb | 4 | ||||
| -rw-r--r-- | test/sections_test.rb | 38 |
3 files changed, 42 insertions, 4 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index e6b47b4b..6ddad584 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -24,6 +24,10 @@ Enhancements:: * Add `--sourcemap` option to the CLI to enable the `:sourcemap` option on the parser (#3569) *@hackingotter* * Allow section ID to be unset by assigning an empty value to the `id` block attribute (#4139) +Compliance:: + + * Don't promote level-0 special section at start of document to document title (#4151) + Bug Fixes:: * Remove unnamespaced selectors in Pygments stylesheet diff --git a/lib/asciidoctor/parser.rb b/lib/asciidoctor/parser.rb index f54d07f6..628b79dc 100644 --- a/lib/asciidoctor/parser.rb +++ b/lib/asciidoctor/parser.rb @@ -123,9 +123,9 @@ class Parser block_attrs = reader.skip_blank_lines ? (parse_block_metadata_lines reader, document) : {} doc_attrs = document.attributes - # special case, block title is not allowed above document title, + # special cases, block style or title is not allowed above document title, # carry attributes over to the document body - if (implicit_doctitle = is_next_line_doctitle? reader, block_attrs, doc_attrs['leveloffset']) && block_attrs['title'] + if (implicit_doctitle = is_next_line_doctitle? reader, block_attrs, doc_attrs['leveloffset']) && (block_attrs['title'] || block_attrs['style']) return document.finalize_header block_attrs, false end diff --git a/test/sections_test.rb b/test/sections_test.rb index 84ecd485..c28e53b1 100644 --- a/test/sections_test.rb +++ b/test/sections_test.rb @@ -616,9 +616,25 @@ context 'Sections' do assert_xpath '//a[text()="Reference Manual"]', output, 1 end - test 'should discard style, role and options shorthand attributes defined on document title' do + test 'should not interpret level-0 section as document title if it has a style' do input = <<~'EOS' - [style#idname.rolename%optionname] + [glossary] + = Document Title + + content + EOS + using_memory_logger do |logger| + doc = document_from_string input + assert_message logger, :ERROR, '<stdin>: line 2: level 0 sections can only be used when doctype is book', Hash + refute doc.header? + assert_nil doc.attributes['title'] + assert_equal 'glossary', doc.blocks[0].attributes['style'] + end + end + + test 'should discard role and options shorthand attributes defined on document title' do + input = <<~'EOS' + [#idname.rolename%optionname] = Document Title content @@ -2111,6 +2127,24 @@ context 'Sections' do assert appendix.numbered end + test 'should not promote level-0 special section in book doctype to document title' do + input = <<~'EOS' + :doctype: book + + [appendix] + = Installation + + Installation details here. + EOS + + doc = document_from_string input + refute doc.header? + assert_nil doc.attributes['title'] + appendix = doc.blocks[0] + assert_equal 'appendix', appendix.sectname + assert_equal 'Appendix A: ', appendix.caption + end + test 'should prefix appendix title by numbered label even when section numbering is disabled' do input = <<~'EOS' [appendix] |
