Class: AsciidoctorExtensions::KrokiProcessor
- Inherits:
-
Object
- Object
- AsciidoctorExtensions::KrokiProcessor
- Includes:
- Asciidoctor::Logging
- Defined in:
- lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb
Overview
Internal processor
Constant Summary collapse
- TEXT_FORMATS =
%w[txt atxt utxt].freeze
- BUILTIN_ATTRIBUTES =
%w[target width height format fallback link float align role caption title cloaked-context subs].freeze
Class Method Summary collapse
-
.process(processor, parent, attrs, diagram_type, diagram_text, logger) ⇒ Object
rubocop:disable Metrics/AbcSize.
Class Method Details
.process(processor, parent, attrs, diagram_type, diagram_text, logger) ⇒ Object
rubocop:disable Metrics/AbcSize
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb', line 150 def process(processor, parent, attrs, diagram_type, diagram_text, logger) doc = parent.document diagram_text = prepend_plantuml_config(diagram_text, diagram_type, doc, logger) # If "subs" attribute is specified, substitute accordingly. # Be careful not to specify "specialcharacters" or your diagram code won't be valid anymore! if (subs = attrs['subs']) diagram_text = parent.apply_subs(diagram_text, parent.resolve_subs(subs)) end attrs.delete('opts') format = get_format(doc, attrs, diagram_type) attrs['role'] = get_role(format, attrs['role']) attrs['format'] = format opts = attrs.filter { |key, _| key.is_a?(String) && BUILTIN_ATTRIBUTES.none? { |k| key == k } && !key.end_with?('-option') } kroki_diagram = KrokiDiagram.new(diagram_type, format, diagram_text, attrs['target'], opts) kroki_client = KrokiClient.new({ server_url: server_url(doc), http_method: http_method(doc), max_uri_length: max_uri_length(doc), source_location: doc.reader.cursor_at_mark, http_client: KrokiHttpClient }, logger) alt = get_alt(attrs) title = attrs.delete('title') = attrs.delete('caption') if TEXT_FORMATS.include?(format) text_content = kroki_client.text_content(kroki_diagram) block = processor.create_block(parent, 'literal', text_content, attrs) else attrs['alt'] = alt attrs['target'] = create_image_src(doc, kroki_diagram, kroki_client) block = processor.create_image_block(parent, attrs) end block.title = title if title block.(, 'figure') block end |