diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2018-04-17 20:33:03 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2018-04-19 00:04:34 -0600 |
| commit | a3fdbc08ca75005ab9644dd7d3ac2e95e25aeaa1 (patch) | |
| tree | f2187f1d0c8a17c3e2a38bc746f792a047f14e52 | |
| parent | 04cd2bd029e7f2ebde32b1f384826a6e11ae50ff (diff) | |
ID in block attributes above document title takes precedence over ID defined inline
- change the behavior of the document title to match the behavior of section titles
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/parser.rb | 17 | ||||
| -rw-r--r-- | test/sections_test.rb | 4 |
3 files changed, 10 insertions, 12 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index c5497d59..61c415ba 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -101,6 +101,7 @@ Improvements / Refactoring:: * coerce value of template_dirs option to an Array (PR #2621) * allow paragraph to masquerade as open block (PR #2412) * move callouts into document catalog (PR #2394) + * document ID defined in block attribute line takes precedence over ID defined inside document title line * skip line comments in name section of manpage (#2584, PR #2585) * always activate extension registry passed to processor (PR #2379) * skip extension registry activation if no groups are registered (PR #2373) diff --git a/lib/asciidoctor/parser.rb b/lib/asciidoctor/parser.rb index 1eabd44b..3cf39211 100644 --- a/lib/asciidoctor/parser.rb +++ b/lib/asciidoctor/parser.rb @@ -152,17 +152,14 @@ class Parser end document.header.source_location = source_location if source_location document.attributes['doctitle'] = section_title = doctitle - # QUESTION: should the id assignment on Document be encapsulated in the Document class? - if (doc_id = document.id) - block_attributes.delete 1 - block_attributes.delete 'id' + if (style = block_attributes.delete 1) + style_attrs = { 1 => style } + parse_style_attribute style_attrs, reader + document.id = (doc_id = style_attrs['id'] || document.id) + elsif (doc_id = block_attributes.delete 'id') + document.id = doc_id else - if (style = block_attributes.delete 1) - style_attrs = { 1 => style } - parse_style_attribute style_attrs, reader - block_attributes['id'] = style_attrs['id'] if style_attrs.key? 'id' - end - document.id = (doc_id = block_attributes.delete 'id') + doc_id = document.id end if (doc_reftext = block_attributes.delete 'reftext') document.attributes['reftext'] = doc_reftext diff --git a/test/sections_test.rb b/test/sections_test.rb index 1b9ebcd8..3f3d4094 100644 --- a/test/sections_test.rb +++ b/test/sections_test.rb @@ -397,7 +397,7 @@ content assert_css 'body#idname', output, 1 end - test 'should use inline id instead of id defined in block attributes' do + test 'should use ID defined in block attributes instead of ID defined inline' do input = <<-EOS [#idname-block] = Document Title [[idname-inline]] @@ -405,7 +405,7 @@ content content EOS output = render_string input - assert_css 'body#idname-inline', output, 1 + assert_css 'body#idname-block', output, 1 end test 'block id above document title sets id on document' do |
