Skip to content

Commit

Permalink
resolves #1606 pass cloaked context to block extension (PR #1986)
Browse files Browse the repository at this point in the history
- pass cloaked context as cloaked-context attribute to process method of custom block extension
  • Loading branch information
mojavelinux committed Jan 3, 2017
1 parent 7f5a490 commit f67f9f6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/asciidoctor/parser.rb
Expand Up @@ -871,14 +871,15 @@ def self.next_block(reader, parent, attributes = {}, options = {})

else
if block_extensions && (extension = extensions.registered_for_block?(block_context, cloaked_context))
# TODO pass cloaked_context to extension somehow (perhaps a new instance for each cloaked_context?)
if (content_model = extension.config[:content_model]) != :skip
if !(pos_attrs = extension.config[:pos_attrs] || []).empty?
AttributeList.rekey(attributes, [nil].concat(pos_attrs))
end
if (default_attrs = extension.config[:default_attrs])
default_attrs.each {|k, v| attributes[k] ||= v }
end
# QUESTION should we clone the extension for each cloaked context and set in config?
attributes['cloaked-context'] = cloaked_context
end
block = build_block block_context, content_model, terminator, parent, reader, attributes, :extension => extension
unless block && content_model != :skip
Expand Down
27 changes: 27 additions & 0 deletions test/extensions_test.rb
Expand Up @@ -556,6 +556,33 @@ def activate registry
end
end

test 'should pass cloaked context in attributes passed to process method of custom block' do
input = <<-EOS
[custom]
****
sidebar
****
EOS

cloaked_context = nil
begin
Asciidoctor::Extensions.register do
block :custom do
on_context :sidebar
process do |doc, reader, attrs|
cloaked_context = attrs['cloaked-context']
nil
end
end
end

render_embedded_string input
assert_equal :sidebar, cloaked_context
ensure
Asciidoctor::Extensions.unregister_all
end
end

test 'should invoke processor for custom block macro' do
input = <<-EOS
snippet::12345[]
Expand Down

0 comments on commit f67f9f6

Please sign in to comment.