diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2019-03-19 18:14:13 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-19 18:14:13 -0600 |
| commit | 5da481e7080ea9c68c3997c1b3d24a789fd0239f (patch) | |
| tree | fe5167d64518c2ff0919910a86c6a7af6c7dfaf6 | |
| parent | 1c5499fae42505651f44f1fd502abe6ee8270d1b (diff) | |
resolves #2861 log dropped lines at info level when attribute-missing=drop-line (PR #3170)
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/parser.rb | 2 | ||||
| -rw-r--r-- | lib/asciidoctor/reader.rb | 2 | ||||
| -rw-r--r-- | lib/asciidoctor/substitutors.rb | 9 | ||||
| -rw-r--r-- | test/attributes_test.rb | 9 | ||||
| -rw-r--r-- | test/document_test.rb | 2 | ||||
| -rw-r--r-- | test/extensions_test.rb | 2 |
7 files changed, 15 insertions, 12 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index d6e2250a..f453d1b3 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -48,6 +48,7 @@ Enhancements / Compliance:: * don't allow block role to inherit from document attribute; only look for role in block attributes (#1944) * split out functionality of -w CLI flag (script warnings) from -v CLI flag (verbose logging) (#3030) * log possible invalid references at debug level (#3030) + * log dropped lines at info level when attribute-missing=drop-line (#2861) * use the third argument of AbstractNode#attr / AbstractNode#attr? to set the name of a fallback attribute to look for on the document (#1934) * change default value of third argument to Abstractnode#attr / AbstractNode#attr? to nil so attribute doesn't inherit by default (#3059) * look for table-frame, table-grid, and table-stripes attributes on document as fallback for frame, grid, and stripes attributes on table (#3059) diff --git a/lib/asciidoctor/parser.rb b/lib/asciidoctor/parser.rb index 95ac652a..3e69f38c 100644 --- a/lib/asciidoctor/parser.rb +++ b/lib/asciidoctor/parser.rb @@ -582,7 +582,7 @@ class Parser end # style doesn't have special meaning for media macros attributes.delete 'style' if attributes.key? 'style' - if (target.include? ATTR_REF_HEAD) && (target = block.sub_attributes target, attribute_missing: 'drop-line').empty? + if (target.include? ATTR_REF_HEAD) && (target = block.sub_attributes target, attribute_missing: 'drop-line', drop_line_severity: :warn).empty? # retain as unparsed if attribute-missing is skip if (doc_attrs['attribute-missing'] || Compliance.attribute_missing) == 'skip' return Block.new(parent, :paragraph, content_model: :simple, source: [this_line]) diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb index 7227a2c0..a8c27925 100644 --- a/lib/asciidoctor/reader.rb +++ b/lib/asciidoctor/reader.rb @@ -1014,7 +1014,7 @@ class PreprocessorReader < Reader def preprocess_include_directive target, attrlist doc = @document if ((expanded_target = target).include? ATTR_REF_HEAD) && - (expanded_target = doc.sub_attributes target, attribute_missing: 'drop-line').empty? + (expanded_target = doc.sub_attributes target, attribute_missing: 'drop-line', drop_line_severity: :warn).empty? shift if (doc.attributes['attribute-missing'] || Compliance.attribute_missing) == 'skip' unshift %(Unresolved directive in #{@path} - include::#{target}[#{attrlist}]) diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb index 37a953c9..7dbfd382 100644 --- a/lib/asciidoctor/substitutors.rb +++ b/lib/asciidoctor/substitutors.rb @@ -416,7 +416,7 @@ module Substitutors # Returns the [String] text with the attribute references replaced with resolved values def sub_attributes text, opts = {} doc_attrs = @document.attributes - drop = drop_line = drop_empty_line = attribute_undefined = attribute_missing = nil + drop = drop_line = drop_line_severity = drop_empty_line = attribute_undefined = attribute_missing = nil text = text.gsub AttributeReferenceRx do # escaped attribute, return unescaped if $1 == RS || $4 == RS @@ -426,7 +426,7 @@ module Substitutors when 'set' _, value = Parser.store_attribute args[0], args[1] || '', @document # NOTE since this is an assignment, only drop-line applies here (skip and drop imply the same result) - if value || (attribute_undefined ||= doc_attrs['attribute-undefined'] || Compliance.attribute_undefined) != 'drop-line' + if value || (attribute_undefined ||= (doc_attrs['attribute-undefined'] || Compliance.attribute_undefined)) != 'drop-line' drop = drop_empty_line = DEL else drop = drop_line = CAN @@ -442,11 +442,12 @@ module Substitutors elsif (value = INTRINSIC_ATTRIBUTES[key]) value else - case (attribute_missing ||= opts[:attribute_missing] || doc_attrs['attribute-missing'] || Compliance.attribute_missing) + case (attribute_missing ||= (opts[:attribute_missing] || doc_attrs['attribute-missing'] || Compliance.attribute_missing)) when 'drop' drop = drop_empty_line = DEL when 'drop-line' - logger.warn %(dropping line containing reference to missing attribute: #{key}) + drop_line_severity ||= (opts[:drop_line_severity] || :info) + logger.send drop_line_severity, %(dropping line containing reference to missing attribute: #{key}) drop = drop_line = CAN when 'warn' logger.warn %(skipping reference to missing attribute: #{key}) diff --git a/test/attributes_test.rb b/test/attributes_test.rb index 26eafe59..cc3e6d46 100644 --- a/test/attributes_test.rb +++ b/test/attributes_test.rb @@ -137,7 +137,7 @@ context 'Attributes' do test 'assigns attribute to empty string if substitution fails to resolve attribute' do input = ':release: Asciidoctor {version}' document_from_string input, attributes: { 'attribute-missing' => 'drop-line' } - assert_message @logger, :WARN, 'dropping line containing reference to missing attribute: version' + assert_message @logger, :INFO, 'dropping line containing reference to missing attribute: version' end test 'assigns multi-line attribute to empty string if substitution fails to resolve attribute' do @@ -147,7 +147,7 @@ context 'Attributes' do EOS doc = document_from_string input, attributes: { 'attribute-missing' => 'drop-line' } assert_equal '', doc.attributes['release'] - assert_message @logger, :WARN, 'dropping line containing reference to missing attribute: version' + assert_message @logger, :INFO, 'dropping line containing reference to missing attribute: version' end test 'resolves attributes inside attribute value within header' do @@ -648,7 +648,7 @@ context 'Attributes' do output = convert_string_to_embedded input para = xmlnodes_at_css 'p', output, 1 refute_includes 'blah blah', para.content - assert_message @logger, :WARN, 'dropping line containing reference to missing attribute: foobarbaz' + assert_message @logger, :INFO, 'dropping line containing reference to missing attribute: foobarbaz' end test "attribute value gets interpretted when converting" do @@ -669,7 +669,7 @@ context 'Attributes' do output = convert_string_to_embedded input assert_match(/Line 1/, output) refute_match(/Line 2/, output) - assert_message @logger, :WARN, 'dropping line containing reference to missing attribute: bogus-attribute' + assert_message @logger, :INFO, 'dropping line containing reference to missing attribute: bogus-attribute' end test 'should not drop line with reference to missing attribute by default' do @@ -974,6 +974,7 @@ context 'Attributes' do output = convert_string_to_embedded input assert_xpath '//p', output, 1 assert_xpath '//p/child::text()', output, 0 + assert_message @logger, :INFO, 'dropping line containing reference to missing attribute: foo' end end diff --git a/test/document_test.rb b/test/document_test.rb index 8a9d5a86..58e833da 100644 --- a/test/document_test.rb +++ b/test/document_test.rb @@ -368,7 +368,7 @@ context 'Document' do refute_empty output assert_css 'script', output, 0 assert_xpath %(//meta[@name="copyright"][@content="(C) OpenDevise"]), output, 1 - assert_message logger, :WARN, 'dropping line containing reference to missing attribute: bootstrap-version' + assert_message logger, :INFO, 'dropping line containing reference to missing attribute: bootstrap-version' end end diff --git a/test/extensions_test.rb b/test/extensions_test.rb index c4ecd9c4..6f2a9501 100644 --- a/test/extensions_test.rb +++ b/test/extensions_test.rb @@ -1002,7 +1002,7 @@ context 'Extensions' do assert_equal 1, doc.blocks.size assert_equal :paragraph, doc.blocks[0].context output = doc.convert - assert_message logger, :WARN, 'dropping line containing reference to missing attribute: gist-ns' + assert_message logger, :INFO, 'dropping line containing reference to missing attribute: gist-ns' end assert_css '.paragraph', output, 1 assert_css '.rolename', output, 0 |
