diff --git a/ruby/Gemfile.lock b/ruby/Gemfile.lock index 26c7c31..85aa447 100644 --- a/ruby/Gemfile.lock +++ b/ruby/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - asciidoctor-kroki (0.10.0) + asciidoctor-kroki (0.10.1) asciidoctor (~> 2.0) GEM diff --git a/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb b/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb index 4e41bba..fa4553e 100644 --- a/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb +++ b/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb @@ -53,6 +53,12 @@ def initialize(name = nil, config = {}) super(name, config) end + # Processes the diagram block or block macro by converting it into an image or literal block. + # + # @param parent [Asciidoctor::AbstractBlock] the parent asciidoc block of the block or block macro being processed + # @param target [String] the target value of a block macro + # @param attrs [Hash] the attributes of the block or block macro + # @return [Asciidoctor::AbstractBlock] a new block that replaces the original block or block macro def process(parent, target, attrs) diagram_type = @name target = parent.apply_subs(target, [:attributes]) @@ -62,7 +68,7 @@ def process(parent, target, attrs) return create_block(parent, :paragraph, link.convert, {}, content_model: :raw) end - unless (path = resolve_target_path(target)) + unless (path = resolve_target_path(parent, target)) logger.error message_with_context "#{diagram_type} block macro not found: #{target}.", source_location: parent.document.reader.cursor_at_mark return create_block(parent, 'paragraph', unresolved_block_macro_message(diagram_type, target), {}) end @@ -80,8 +86,10 @@ def process(parent, target, attrs) attr_reader :logger - def resolve_target_path(target) - target + # @param parent [Asciidoctor::AbstractBlock] the parent asciidoc block of the block or block macro being processed + # @param target [Asciidoctor::Reader, String] the target value of a block macro + def resolve_target_path(parent, target) + parent.normalize_system_path(target) end def read_allowed?(_target) diff --git a/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/version.rb b/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/version.rb index d8685f1..bb03ebf 100644 --- a/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/version.rb +++ b/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/version.rb @@ -2,6 +2,6 @@ module Asciidoctor module AsciidoctorKroki - VERSION = '0.10.0' + VERSION = '0.10.1' end end diff --git a/ruby/spec/asciidoctor_kroki_block_macro_spec.rb b/ruby/spec/asciidoctor_kroki_block_macro_spec.rb index f70d8fd..13100fe 100644 --- a/ruby/spec/asciidoctor_kroki_block_macro_spec.rb +++ b/ruby/spec/asciidoctor_kroki_block_macro_spec.rb @@ -9,10 +9,18 @@ describe ::AsciidoctorExtensions::KrokiBlockMacroProcessor do context 'convert to html5' do it 'should catch exception if target is not readable' do + class PlainResolutionKrokiMacroProcessor < ::AsciidoctorExtensions::KrokiBlockMacroProcessor + def resolve_target_path(_parent, target) + target + end + end + registry = Asciidoctor::Extensions.create do + block_macro PlainResolutionKrokiMacroProcessor, 'plantuml' + end input = <<~'ADOC' plantuml::spec/fixtures/missing.puml[svg,role=sequence] ADOC - output = Asciidoctor.convert(input, standalone: false) + output = Asciidoctor.convert(input, standalone: false, extension_registry: registry) (expect output).to eql %(
Unresolved block macro - plantuml::spec/fixtures/missing.puml[]