From 9e30b34147059ce22f37102234b570da47872c6a Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Fri, 16 Apr 2021 01:10:17 -0600 Subject: [PATCH] resolves #2586 ensure document attributes unset in parent document remain unset in AsciiDoc table cell (nested) document --- CHANGELOG.adoc | 1 + lib/asciidoctor/document.rb | 14 ++++---- test/tables_test.rb | 72 +++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 1281fc7899..015e3c5849 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -18,6 +18,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[ Bug Fixes:: * Do not allow AsciiDoc table cell to set document attribute that was unset from the API (except compat-mode and toc) (#4017) + * Ensure document attributes unset in parent document remain unset in AsciiDoc table cell (nested) document (#2586) * 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) diff --git a/lib/asciidoctor/document.rb b/lib/asciidoctor/document.rb index f857df7b7d..76a3af91e7 100644 --- a/lib/asciidoctor/document.rb +++ b/lib/asciidoctor/document.rb @@ -264,7 +264,7 @@ def initialize data = nil, options = {} parent_doctype = attr_overrides.delete 'doctype' # QUESTION if toc is hard unset in parent document, should it be hard unset in nested document? attr_overrides.delete 'toc' - attr_overrides.delete 'toc-placement' + @attributes['toc-placement'] = (attr_overrides.delete 'toc-placement') || 'auto' attr_overrides.delete 'toc-position' @safe = parent_doc.safe @attributes['compat-mode'] = '' if (@compat_mode = parent_doc.compat_mode) @@ -339,11 +339,13 @@ def initialize data = nil, options = {} (@options = options).freeze attrs = @attributes - attrs['attribute-undefined'] = Compliance.attribute_undefined - attrs['attribute-missing'] = Compliance.attribute_missing - attrs.update DEFAULT_ATTRIBUTES - # TODO if lang attribute is set, @safe mode < SafeMode::SERVER, and !parent_doc, - # load attributes from data/locale/attributes-.adoc + unless parent_doc + attrs['attribute-undefined'] = Compliance.attribute_undefined + attrs['attribute-missing'] = Compliance.attribute_missing + attrs.update DEFAULT_ATTRIBUTES + # TODO if lang attribute is set, @safe mode < SafeMode::SERVER, and !parent_doc, + # load attributes from data/locale/attributes-.adoc + end if standalone # sync embedded attribute with :standalone option value diff --git a/test/tables_test.rb b/test/tables_test.rb index a6ba9d6ddb..0f15359fee 100644 --- a/test/tables_test.rb +++ b/test/tables_test.rb @@ -1421,6 +1421,78 @@ assert_xpath '//td[@class="icon"]/*[@class="title"][text()="Note"]', result, 1 end + test 'should keep attribute unset in AsciiDoc table cell if unset in parent document' do + input = <<~'EOS' + :!sectids: + :!table-caption: + + == Outer Heading + + .Outer Table + |=== + a| + + == Inner Heading + + .Inner Table + !=== + ! table cell + !=== + |=== + EOS + + result = convert_string_to_embedded input + assert_xpath 'h2[id]', result, 0 + assert_xpath '//caption[text()="Outer Table"]', result, 1 + assert_xpath '//caption[text()="Inner Table"]', result, 1 + end + + test 'should allow attribute unset in parent document to be set in AsciiDoc table cell' do + input = <<~'EOS' + :!sectids: + + == No ID + + |=== + a| + + == No ID + + :sectids: + + == Has ID + |=== + EOS + + result = convert_string_to_embedded input + headings = xmlnodes_at_css 'h2', result + assert_equal 3, headings.size + assert_nil headings[0].attr :id + assert_nil headings[1].attr :id + assert_equal '_has_id', (headings[2].attr :id) + end + + test 'should not allow locked attribute unset in parent document to be set in AsciiDoc table cell' do + input = <<~'EOS' + == No ID + + |=== + a| + + == No ID + + :sectids: + + == Has ID + |=== + EOS + + result = convert_string_to_embedded input, attributes: { 'sectids' => nil } + headings = xmlnodes_at_css 'h2', result + assert_equal 3, headings.size + headings.each {|heading| assert_nil (heading.attr :id) } + end + test 'AsciiDoc content' do input = <<~'EOS' [cols="1e,1,5a"]