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
- PLANTUML_TYPES =
%i[plantuml c4plantuml].freeze
Class Method Summary collapse
-
.process(processor, parent, attrs, diagram_type, diagram_text, logger, resource_path: nil) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity.
Class Method Details
.process(processor, parent, attrs, diagram_type, diagram_text, logger, resource_path: nil) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb', line 164 def process(processor, parent, attrs, diagram_type, diagram_text, logger, resource_path: nil) doc = parent.document diagram_text = prepend_plantuml_config(diagram_text, diagram_type, doc, logger) diagram_text = preprocess_plantuml_includes(diagram_text, diagram_type, doc, resource_path, 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') # Apply the option defined on the block/macro or, as a fallback, the document-wide kroki-default-options. if (option = get_option(attrs, doc)) && option != 'none' attrs["#{option}-option"] = '' end 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') caption = 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 apply_image_src(attrs, create_image_src(doc, kroki_diagram, kroki_client, logger)) block = processor.create_image_block(parent, attrs) end block.title = title if title block.assign_caption(caption, 'figure') block end |