Skip to content

Commit

Permalink
resolves #382 set alt value
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Aug 31, 2022
1 parent 834d001 commit a1c7d0e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ Here's a list of all attributes used in the built-in HTML 5 converter:
- `float`
- `align`
- `role`
- `title` (used to define an alternative text description of the diagram)

**Options**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ def process(processor, parent, attrs, diagram_type, diagram_text, logger)
if (subs = attrs['subs'])
diagram_text = parent.apply_subs(diagram_text, parent.resolve_subs(subs))
end
title = attrs.delete('title')
caption = attrs.delete('caption')
attrs.delete('opts')
format = get_format(doc, attrs, diagram_type)
attrs['role'] = get_role(format, attrs['role'])
Expand All @@ -162,11 +160,14 @@ def process(processor, parent, attrs, diagram_type, diagram_text, logger)
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'] = get_alt(attrs)
attrs['alt'] = alt
attrs['target'] = create_image_src(doc, kroki_diagram, kroki_client)
block = processor.create_image_block(parent, attrs)
end
Expand Down
15 changes: 15 additions & 0 deletions ruby/spec/asciidoctor_kroki_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
<div class="content">
<img src="https://kroki.io/plantuml/svg/eNpLzMlMTlXQtVNIyk-yUshIzcnJBwA9iwZL" alt="Diagram">
</div>
</div>)
end
it 'should use the title attribute as the alt value' do
input = <<~'ADOC'
[plantuml,title="Alice saying hello to Bob"]
....
alice -> bob: hello
....
ADOC
output = Asciidoctor.convert(input, standalone: false)
(expect output).to eql %(<div class="imageblock kroki">
<div class="content">
<img src="https://kroki.io/plantuml/svg/eNpLzMlMTlXQtVNIyk-yUshIzcnJBwA9iwZL" alt="Alice saying hello to Bob">
</div>
<div class="title">Figure 1. Alice saying hello to Bob</div>
</div>)
end
it 'should use png if kroki-default-format is set to png' do
Expand Down

0 comments on commit a1c7d0e

Please sign in to comment.