summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2018-05-07 23:56:23 -0600
committerDan Allen <dan.j.allen@gmail.com>2018-05-08 00:00:02 -0600
commit83ff5e90fa8510a8a5ebfa61c52f2a2c5670841e (patch)
tree17c5910b305e8ee42a6823fa4835f097620f01d3
parent9aefdeed07b2a72b7518c80b1e67239b433f6018 (diff)
resolves #2761 substitute attribute references in attrlist of include directive
-rw-r--r--lib/asciidoctor/reader.rb6
-rw-r--r--test/reader_test.rb13
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb
index e468d55a..851c1dc5 100644
--- a/lib/asciidoctor/reader.rb
+++ b/lib/asciidoctor/reader.rb
@@ -852,7 +852,8 @@ class PreprocessorReader < Reader
elsif include_processors? && (ext = @include_processor_extensions.find {|candidate| candidate.instance.handles? expanded_target })
shift
# FIXME parse attributes only if requested by extension
- ext.process_method[@document, self, expanded_target, attrlist ? (AttributeList.new attrlist).parse : {}]
+ parsed_attributes = attrlist ? AttributeList.new((attrlist.include? ATTR_REF_HEAD) ? (@document.sub_attributes attrlist) : attrlist).parse : {}
+ ext.process_method[@document, self, expanded_target, parsed_attributes]
true
# if running in SafeMode::SECURE or greater, don't process this directive
# however, be friendly and at least make it a link to the source document
@@ -865,7 +866,8 @@ class PreprocessorReader < Reader
return
end
- parsed_attributes = attrlist ? (AttributeList.new attrlist).parse : {}
+ # QUESTION should we use (@document.parse_attributes attrlist, [])?
+ parsed_attributes = attrlist ? AttributeList.new((attrlist.include? ATTR_REF_HEAD) ? (@document.sub_attributes attrlist) : attrlist).parse : {}
inc_path, target_type, relpath = resolve_include_path expanded_target, attrlist, parsed_attributes
return inc_path unless target_type
diff --git a/test/reader_test.rb b/test/reader_test.rb
index a2aeefd0..2c392232 100644
--- a/test/reader_test.rb
+++ b/test/reader_test.rb
@@ -1260,6 +1260,19 @@ include::fixtures/basic-docinfo.xml[lines=2..3, indent=0]
assert_equal "<year>2013</year>\n<holder>Acme™, Inc.</holder>", result
end
+ test 'should substitute attribute references in attrlist' do
+ input = <<-EOS
+:name-of-tag: snippetA
+include::fixtures/include-file.asciidoc[tag={name-of-tag}]
+ EOS
+
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
+ assert_match(/snippetA content/, output)
+ refute_match(/snippetB content/, output)
+ refute_match(/non-tagged content/, output)
+ refute_match(/included content/, output)
+ end
+
test 'should fall back to built-in include directive behavior when not handled by include processor' do
input = <<-EOS
include::fixtures/include-file.asciidoc[]