Class: AsciidoctorExtensions::KrokiBlockProcessor
- Inherits:
-
Extensions::BlockProcessor
- Object
- Extensions::BlockProcessor
- AsciidoctorExtensions::KrokiBlockProcessor
- Includes:
- Asciidoctor::Logging
- Defined in:
- lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb
Overview
A block extension that converts a diagram into an image.
Instance Method Summary collapse
-
#initialize(name = nil, config = {}) ⇒ KrokiBlockProcessor
constructor
A new instance of KrokiBlockProcessor.
- #process(parent, reader, attrs) ⇒ Object
Constructor Details
#initialize(name = nil, config = {}) ⇒ KrokiBlockProcessor
Returns a new instance of KrokiBlockProcessor.
27 28 29 30 |
# File 'lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb', line 27 def initialize(name = nil, config = {}) @logger = (config || {}).delete(:logger) { ::Asciidoctor::LoggerManager.logger } super end |
Instance Method Details
#process(parent, reader, attrs) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb', line 32 def process(parent, reader, attrs) diagram_type = @name role = attrs['role'] source_location = reader.cursor diagram_text = reader.string KrokiProcessor.process(self, parent, attrs, diagram_type, diagram_text, @logger) rescue => e # rubocop:disable Style/RescueStandardError # Matches the JavaScript/Node.js extension: a failure talking to the Kroki server (network # error, non-2xx response, unexpected content-type) shouldn't abort the whole document # conversion, so it's degraded to a warning and the raw diagram source is kept visible. logger.warn "Skipping #{diagram_type} block: #{e.}", source_location: source_location attrs['role'] = role ? "#{role} kroki-error" : 'kroki-error' create_block(parent, attrs['cloaked-context'], diagram_text, attrs) end |